More MVC serilog question

206 views
Skip to first unread message

Nicolas Tenoutasse

unread,
May 30, 2016, 9:24:46 AM5/30/16
to Serilog
Hello,

after 
loggerFactory.AddSerilog(Log.Logger);

How do you get it back from MVC?
of course, you get ILogger<XXXController> logger injected in your controller constructor but is there a way to get back a Serilog ILogger?

Nicolas

nblum...@nblumhardt.com

unread,
May 30, 2016, 6:15:40 PM5/30/16
to Serilog
Hi Nicolas,

I think to do this you need to configure the Microsoft.Extensions.DependencyInjection system so that Serilog's ILogger is registered.

I haven't looked into how this should be done, but an example here does the same thing for Autofac: https://github.com/nblumhardt/autofac-serilog-integration/ - if you have a chance to try porting it, it'd be very interesting to hear about your experiences!

Regards,
Nick

Nicolas Tenoutasse

unread,
May 31, 2016, 9:50:02 AM5/31/16
to Serilog
One easy way to do get back the global Log.logger without access global vars directly is to do 
services.AddInstance<Serilog.ILogger>(Log.Logger);
in the ConfigureServices method and then require a Serilog.ILogger in the constructor but you don't get all the context...

Since there is no Serilog.Ilogger<> defined, you need much more effort to implement it I believe

Nicolas
Reply all
Reply to author
Forward
0 new messages