Read from IConfiguration without SectionKey
See original GitHub issueI’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” 😃
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:11 (8 by maintainers)
👍 I’ll come up with something based on your suggestions
Ah, right. Today, all overloads throw
ArgumentNullException
if the providedsectionName
is null. But changing null to instead indicate that the given IConfiguration is the serilog section would work. As you say - slightly strange, but seems perfectly fine given the circumstances 😃I was going to suggest making
sectionName
nullable, but seems like the project doesn’t have nullable reference types enabled anyway, so I guess that’s not an issue.