-
Notifications
You must be signed in to change notification settings - Fork 34
Adds SerilogServiceCollectionExtensions #19
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
Adds SerilogServiceCollectionExtensions #19
Conversation
Allows for more flexibility when configuring serilog services during startup. In some cases we don't want to use the serilog static Log and we aren't able to pre-create an ILogger before the HostBuilder is configured. We will create our own serilog logger during Configure Services and then we need to configure the rest of serilog services which isn't possible without copying all this code it would be nicer to just expose these methods so people can use them.
using Serilog.Extensions.Logging; | ||
|
||
namespace Serilog | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Consumed by user code | ||
collection.AddSingleton<IDiagnosticContext>(diagnosticContext); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
if (providers != null) | ||
{ | ||
collection.AddSingleton<ILoggerFactory>(services => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Shazwazza @nblumhardt do you mind renaming IServiceCollection collection
to IServiceCollection services
and services
(IServiceProvider
arg) to provider
? The current naming is confusing.
Hi Shannon, thanks for the PR 👍 RE the static But, there are some limitations at the moment you're probably hitting, namely, https://github.com/nblumhardt/serilog-reload/blob/dev/example/WebExample/Program.cs#L38 if you have a chance. Would having access to I'd be hesitant to expose Cheers, |
Hi @nblumhardt , for our scenario we have our own logger abstraction and serilog is it's implementation. During our own configuration logic we need to create a serilog logger and configure it and then pass it into our own dependency graph. This all occurs in ConfigureServices in our own ext method. Unfortunately we cannot use any of the current provided serilog ext methods for this scenario. The overload with the |
Cool, thanks for the follow-up, Shannon 👍 |
Sure thing, let me know if/when you want me to adjust any of this code, or if you just want to close this and re-submit another PR down the road. |
Thanks! Closing for now - still more changes to come in this area, #20 just shook up service registration a bit. |
Allows for more flexibility when configuring serilog services during startup. In some cases we don't want to use the serilog static Log and we aren't able to pre-create an ILogger before the HostBuilder is configured. We will create our own serilog logger during Configure Services and then we need to configure the rest of serilog services which isn't possible without copying all this code it would be nicer to just expose these methods so people can use them.