serilog / serilog-extensions-hosting

Serilog logging for Microsoft.Extensions.Hosting
Apache License 2.0
141 stars 34 forks source link

CreateBootstrapLogger doesn't work with non-static Logger #74

Closed gkinsman closed 2 days ago

gkinsman commented 1 year ago

Hi there!

I'm kicking the tyres on CreateBootstrapLogger so that we can pull our log sink config from a secure store. To support parallel test running we don't use a static logger and instead inject it, but I don't see an override of UseSerilog/AddSerilog that accepts both an ILogger and a reconfiguration callback.

This code appears to only check to see if the static logger exists - should there perhaps be an overload that just accepts an ILogger and checks if it or the static logger is reloadable? Happy to add it if this is the right way to go :)

https://github.com/serilog/serilog-extensions-hosting/blob/52f29a676444e58015863ab92c1432357d0fa03f/src/Serilog.Extensions.Hosting/SerilogServiceCollectionExtensions.cs#L141-L144

nblumhardt commented 1 year ago

Thanks for the note, @gkinsman! Sorry about the slow reply - just got back from a short vacation :-)

I might need a bit more context around what your test code looks like, I'm not sure I can really wrap my head around the scenario.

Just to try to fill in the picture - if you have an ILogger already in hand, could you (for example) try casting it to ReloadableLogger and call Reload yourself, before passing it through to AddSerilog?

nblumhardt commented 2 days ago

Closing this one as stale, hope you were able to figure out a solution.