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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With