-
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 inline initialization delegate #177
Conversation
IServiceProvider parameter is named 'serviceProvider', IServiceCollection parameter is named 'services'.
@@ -46,26 +46,26 @@ public static class SerilogWebHostBuilderExtensions | |||
{ | |||
if (builder == null) throw new ArgumentNullException(nameof(builder)); | |||
|
|||
builder.ConfigureServices(collection => | |||
builder.ConfigureServices(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.
👍
Looking great! I think it may actually be better to land the Joining this with the existing overload is tempting, but adding a new one will improve backwards compatibility, so might be the best bet, initially. Let me know if you need any further info. Thanks for taking this on, Ralph! 👍 👍 |
Thank you for your encouragement, Nick. I must admit that I find it rather verbose and (from a user perspective) difficult to understand that the integration with ASP.NET Core is layered; serilog-aspnetcore is using components from both serilog-extensions-hosting and serilog-extensions-logging. I know this comes from the desire to have a fine-grained support model, but it can be quite confusing nonetheless. We should also keep in mind that ASP.NET Core 2.1 is on LTS mode and also needs to remain supported. B.t.w, https://github.com/serilog/serilog-extensions-hosting/blob/dev/README.md explicitly states that
I agree on adding the additional overload for backward compatibility. |
Ok, I've added back the It would be nice if somebody could provide a bit more context on why this option exists in the first place. The present XML doc is not particularly helpful in this respect
I assume what we mean is that when setting this option Implementation-wise, this gets rather tricky, since on the new overload we move the logger creation into the factory delegate for the Any ideas? |
Hi @ralphhendriks - RE RE the initialization order issue... 🤔 hmmmmmmm.... I guess it would be normal to expect that (This kind of thing is why I always initialized |
Hi @ralphhendriks! I dug into the upstream Serilog.Extensions.Hosting and managed to expose serilog/serilog-extensions-hosting#20 I am not sure whether the code there would be a good basis for this version, but, I did end up working through the various issues so there could be some inspiration. Since |
Hi @nblumhardt thanks for the nudge ;) I looked at serilog/serilog-extensions-hosting#20 and I think that it might be very useful here. As I wanted to play with the new overload, I looked at the sample project in Serilog.Extensions.Hosting. It then realized that this sample was still targeting Overseeing how Microsoft deprecated the I'd suggest that we put this PR on ice now, and instead focus on getting the docs and samples in Serilog.Extensions.Hosting improved. If agree I'd like to add specific samples for early/late initialization, as well as adding this to the readme. Please let me know your thoughts. |
That sounds great, @ralphhendriks, thanks for all the help 👍 |
I'll close this for now, we can reopen and revisit in future if our thinking evolves. |
This PR adds an overload for
UseSerilog
that enables access toIServiceProvider
in the configuration delegate. This allows users to query the MS.DI container when configuring the logger. See discussion in #169.An example where this might be useful is for configuring the Application Insights sink. Microsoft have now deprecated the
TelemetryConfiguration.Active
singleton. Current advice to set up the AI sink is to still use this deprecated singleton. It would be more elegant and more in line with Microsoft's advised use to do something likeTO DO
writeToProviders
.preserveStaticLogger
._
for theserviceProvider
parameter.