autofac-serilog-integration
autofac-serilog-integration copied to clipboard
Doesn't add SourceContext in ASP.Net 5 controllers with ILogger injected
Doesn't add SourceContext in ASP.Net 5 controllers with ILogger injected
Controller get registered with the Registration.Preparing event, but doesn't appear that this ever gets called for a controller when the controller is instantiated by the container...not sure why.
Thanks for the heads-up Eric. I'm not sure about how this code will go on the new versions of ASP.NET/Autofac - I haven't tried updating it just yet.
If you drop the two main source files - ContextualLoggingModule.cs
and the SerilogContainerBuilderExtensions.cs
files directly into your project you may be able to debug through this scenario.
I'll try to investigate as soon as I have an opportunity - still a lot of work to do on Serilog fundamentals for v2 however :-)
Sure no worries...I'm also pressed for time at the moment or i would look further...I'll take a look if i get a chance.
I have this same issue too. I've had a go at what @nblumhardt suggested and found that only adding SourceContext
here had any effect.
It's really strange. This line of code gets executed but doesn't have any effect. Looking at the value of registration.Activator.LimitType
in these calls, it seems like my controllers and middleware aren't coming in here. I'm not sure what to make of that?
I'm happy to play around with this if someone can point me in a direction of hope. It's obviously very useful to know where your log messages are coming from, and even more useful not to need to ForContext("SourceContext", GetTypeInfo().Name")
every time you get an ILogger
injected :+1:
Thanks for the follow-up @zaccharles. Are you using Autofac 4.x? The machinery required for this is only in 4.0 (pre-release), not 3.x.
Yeah I'm using 4.0.0-rc3-309
.
Interesting, thanks. I'm not sure whether the "Autofac.AutowiringPropertyInjector.InstanceType"
parameter is present in all conditions - needs some debugging into the Autofac side of things I'd guess.
Looking at this again, we should probably only call ForContext
here if Activator.LimitType
is not typeof(object)
.
https://github.com/nblumhardt/autofac-serilog-integration/blob/dev/src/AutofacSerilogIntegration/ContextualLoggingModule.cs#L95
(Same code repeats for property injection a few lines lower.)