Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Serilog with Castle Windsor LoggingFacility

I currently have an application that makes use of Castle Windsor for Ioc. I now want to change the logging framework for log4net to Serilog.

The following configures things for log4net:

IocManager.Instance.IocContainer.AddFacility<LoggingFacility>(f => f.UseLog4Net().WithConfig("log4net.config"));

There is however no UseSerilog() and looking at how UseLog4Net() is implemented it ultimately calls:

LogUsing(LoggerImplementation.Log4net)

however the LoggerImplementation enum does not have a Serilog member. So how do I tell Castle to use Serilog as my preferred logging framework?

like image 872
TheEdge Avatar asked Mar 13 '23 15:03

TheEdge


1 Answers

We didn't release a new version of Windsor with a Serilog member in the enumeration, however if you look at the implementation of LoggingFacility you'll see that the enumeration members (e.g. log4net) we're just getting loaded by reflection.

You can easily use LogUsing<T>() to provide the SerilogFactory provided by Castle Core:

var container = new WindsorContainer();
container.AddFacility<LoggingFacility>(f => f.LogUsing<SerilogFactory>());

We also deprecated the Logging Facility's LoggerImplementation enumeration in Windsor 4.1.0, LogUsing<T> is the recommended method.

like image 106
Jonathon Rossi Avatar answered Mar 24 '23 21:03

Jonathon Rossi