-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read from IConfiguration without SectionKey #289
Comments
I had a quick look and can't spot a way to achieve this currently. Whipping up your own Longer term we might look at accepting a Any more info about why/how you're hitting this requirement? Thanks! |
I've inherited a code base where IConfigurations are distributed already-zoomed-into. Still, is there a reason I'm not able to give Serilog exactly what it needs? It doesn't feel right to provide it with the entire outer configuration block. And if there are reasons, why is that the default? |
@krafs thanks for the reply. Perhaps you're right - it could just be historical accident at this point. If you're interested in investigating further and putting a PR together, it seems reasonable to take a closer look 👍 |
@krafs , @nblumhardt the reason why This is why root configuration is needed, so it is probably "by design" issue. |
Thanks for the note @skomis-mm! I think where this gets confusing is that Unless I'm misunderstanding the situation, I think the desire to pass both the root configuration and the one to read from as the same argument might be problematic - going back in time, would we consider separating them to allow something like this? .ReadFrom.Configuration(configuration.GetSection("MySerilog"), root: configuration) where the second |
Indeed.. 🤔 I beleive the intent was to have overloads of
Looks good to me. 👍 Thoughts? |
Seems like a reasonable set of trade-offs 👍 |
I feel like the best fit would have been as an overload for If we do add it to |
I'm not 100% sure it would actually conflict - if we just add the // Section name defaults to "Serilog", argument is assumed to be at the root, everything
// works as it does today
.ReadFrom.Configuration(configuration)
// Passed-in configuration is the Serilog section, root not available
.ReadFrom.Configuration(configuration, sectionName: null)
// Passed-in configuration is the Serilog section, root supplied for MSSQL and any other
// sinks that need it (probably quite uncommon)
.ReadFrom.Configuration(configuration, sectionName: null, root: ...) Passing a null |
Ah, right. Today, all overloads throw I was going to suggest making |
👍 I'll come up with something based on your suggestions |
I'm using Serilog.Settings.Configuration to configure Serilog, and I came across an issue.
If I have an IConfiguration that consists of the Serilog-section, how can I configure Serilog with it?
ConfigurationLoggerConfigurationExtensions.ConfigurationSection
only takes an IConfigurationSection, whilst I have an IConfiguration. And even if I did have a section - it's marked as obsolete.ConfigurationLoggerConfigurationExtensions.Configuration
takes an IConfiguration, but it requires an IConfiguration that is one step back, so it can use the sectionKey to get into it.Now, I understand that you can't just add an overload to the abovementioned method, because an overload without the sectionkey already defaults to the key being "Serilog".
Or is there perhaps some other way that I've missed? Apart from "just provide an IConfiguration that isn't already zoomed in to the Serilog section" :)
The text was updated successfully, but these errors were encountered: