question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Read from IConfiguration without SectionKey

See original GitHub issue

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” 😃

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
skomis-mmcommented, Dec 8, 2021

👍 I’ll come up with something based on your suggestions

1reaction
krafscommented, Dec 8, 2021

Ah, right. Today, all overloads throw ArgumentNullException if the provided sectionName 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Access to configuration without dependency injection
I was wondering if there was a way to access Configuration (Microsoft.Extensions.Configuration) without the use of dependency injection.
Read more >
Configuration in ASP.NET Core
Learn how to use the Configuration API to configure AppSettings in an ASP.NET Core app.
Read more >
Configuration providers - .NET
Discover how to configure .NET apps using the configuration provider API and the available configuration providers.
Read more >
A Better Way to Inject AppSettings in Asp.NET Core
The idea of defining configuration settings and being able to access them anywhere using an injected instance of IConfiguration .
Read more >
4.1 Configuration File Syntax
The section names and section keys consist of a sequence of one or more letters, digits, or underscores ( _ ). No other...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found