serilog-aspnetcore icon indicating copy to clipboard operation
serilog-aspnetcore copied to clipboard

Inject `ILogger` into `RequestLoggingMiddleware`

Open julealgon opened this issue 5 years ago • 4 comments

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.

julealgon avatar Oct 21 '20 17:10 julealgon

Thanks for the suggestion, I think this was raised previously, we can take another look 👍

nblumhardt avatar Oct 21 '20 21:10 nblumhardt

It was raised by me.

sungam3r avatar Oct 21 '20 22:10 sungam3r

I wasn't aware this had been raised previously. If there is a duplicate issue, please feel free to close @nblumhardt / @sungam3r .

julealgon avatar Nov 02 '20 17:11 julealgon

It was raised here https://github.com/serilog/serilog-aspnetcore/pull/183#discussion_r398214778

sungam3r avatar Nov 02 '20 19:11 sungam3r