serilog-aspnetcore
serilog-aspnetcore copied to clipboard
Inject `ILogger` into `RequestLoggingMiddleware`
Is your feature request related to a problem? Please describe.
The way RequestLoggingMiddleware currently fetches the ILogger instance is through the options class and fallback to the static logger. I believe this design forces unnecessary changes when using non-static registrations for Serilog as it forces one to manually pass in the ILogger instance on the UseSerilogRequestLogging call.
Describe the solution you'd like
Make it so that ILogger is injected into the middleware by the standard dependency injection mechanism, so that any registered ILogger is naturally used without requiring manual wiring.
Describe alternatives you've considered
I'm personally not fond of dealing with static variables, so while I understand this is not an issue when using Log.Logger, I'd rather not do that in my projects if at all possible.
To make it work, I had to manually inject ILogger into the Configure method and pass it along in the configuration delegate.
Thanks for the suggestion, I think this was raised previously, we can take another look 👍
It was raised by me.
I wasn't aware this had been raised previously. If there is a duplicate issue, please feel free to close @nblumhardt / @sungam3r .
It was raised here https://github.com/serilog/serilog-aspnetcore/pull/183#discussion_r398214778