Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I have to resolve ILogger with Castle Windsor?

All of this code is my own libary to be used by my client consumer applications I have exactly the same installer as in the documentation found here. I also have a bootstrapper pretty much the same as found here, except I use: _bootStrapContainer = new WindsorContainer().Install(FromAssembly.Named("MyAssembly"));

I thought the installer would inject the Castle.Core.Logging.ILogger into the MyLogger class below but I always get null logger unless I resolve the MyLogger.Logger like this:

MyLogger lgr = new MyLogger();            
lgr.Logger = container.Resolve<ILogger>();

So my question is do I always have to resolve or am I not doing something correct during registration?

using Castle.Core.Logging;

public class MyLogger
{
   private ILogger _logger = NullLogger.Instance;

   public ILogger Logger
   {
       get
       {
           return _logger;
       }
       set
       {
           _logger = value;
       }
    } 
}
like image 254
OutOFTouch Avatar asked Sep 03 '25 17:09

OutOFTouch


1 Answers

You need to register the Windsor logging facility to enable Windsor to resolve the Logger property for you.

Here is an example of setting up the logging facility using xml and using code

Basically it boils down to:

container.AddFacility<LoggingFacility>(f => f.UseLog4Net());
like image 156
rivethead_ Avatar answered Sep 05 '25 14:09

rivethead_