27. August 2012 03:29
I am using Castle Windsor for my dependency injection and AOP.
Castle also has Logging Facility implemented in Log4net.
The problem with facility or constructur injection: in some part of application Castle Container is not ready yet (Global.asax, installer or ControllerFactory when you want to have logging) so you have to roll your own Log4Net code.
Castle.Services.Logging.Log4netIntegration has Log4Net wrapper that we can use. The wrapper already handle IsDebugEnabled etc. we just use ILogger.Info, ILogger.Error, etc.)
simple usage: Just create an instance of Log4netFactory and create the implementation of Castle.Core.Logging.ILogger
Log4netFactory _log4NetFactory = new Log4netFactory();
ILogger logger = _log4NetFactory.Create(this.GetType());
Source code for Log4netLogger is available at Castle Project at GitHub
If you want to improve your logger performance you might want to read this link AOP With castle–Part 3-The first interceptor . This article show how to use dictionary as a cache to store your class loggers.