-
Notifications
You must be signed in to change notification settings - Fork 207
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
Expose 'IServiceProvider' on new 'UseSerilog' overload #169
Comments
Agree, exposing |
Good suggestion. However, we should be aware that
will cause logging to only be configured properly after the call to |
Currently, we have the following two extension methods on UseSerilog(
this IWebHostBuilder builder,
ILogger logger = null,
bool dispose = false,
LoggerProviderCollection providers = null) and for inline initialization UseSerilog(
this IWebHostBuilder builder,
Action<WebHostBuilderContext, LoggerConfiguration> configureLogger,
bool preserveStaticLogger = false,
bool writeToProviders = false) Would it be sufficient (as a first step) to add a third overload, also for inline initialization UseSerilog(
this IWebHostBuilder builder,
Action<WebHostBuilderContext, LoggerConfiguration, IServiceProvider> configureLogger,
bool preserveStaticLogger = false,
bool writeToProviders = false) Would that do it for you, @julealgon? |
Yep, that sounds like what I'd do as well from the library side @ralphhendriks . As long as I can tap into the container during configuration I'm good :) |
👍 would be great to see what this entails. |
Very much need this, things like the DB connection string are encrypted, and it's decryption is handled by an injectable service. I'm very unsure of how to configure serilog to actually write to our DB when I require DI support to configure it. |
Related, but WIP: https://github.com/nblumhardt/serilog-reload |
Shipped in 3.4.0 (via version 3.1.0 of Serilog.Extensions.Hosting) |
The existing
UseSerilog
overloads do not provide access to the underlyingIServiceProvider
and thus don't support any kind of dependency injection.I needed to check a settings class on my side using
IOptions<T>
and use these values as paraments to sink configuration. I ended up moving the log configuration into the startup class, dropping the use ofUseSerilog
and instead relying onILoggerFactory.AddSerilog
inside a custom configuration class that I injected inside the Startup'sConfigure
method.If the
IServiceProvider
used in the singleton registration insideUseSerilog
was exposed as one of the parameters, I could've leveraged that to fetch my options instead.From what I gathered from the implementation, it would just be a matter of moving some of the code inside the
AddSingleton
lambda, firing the user-provided lambda there and thus having access to theIServiceProvider
.The text was updated successfully, but these errors were encountered: