I would like to use Common.Logging to remove dependencies on a specific logging framework, but I'm not sure how to wire up the ILog interface using the Castle Windsor IoC container. Is there a way to do this? Thanks!
2 Answers
Do you really want to do both? (Use Common.Logging AND inject it via Castle Windsor IoC?) Using Common.Logging allows your app to NOT have a hard dependency on a specific logging framework (e.g. log4net, NLog, Enterprise Logging). I don't use Castle, but my understanding is that its logging facility has a similar goal. You can configure Castle Windsor to use a specific logging framework (such as log4net or NLog), but your application does not need to be aware of which logging framework is ultimately being used.
Injecting Common.Logging via Castle Windsor seems like wearing a belt AND suspenders to hold your pants up! You would be injecting a logging abstraction via Castle Windsor's own logging abstraction factility!
My guess is that you really want to use one technology or the other (Common.Logging or Castle Windsor's logging facility).
If you really do want to inject Common.Logging via Castle Windsor, you might find this link useful:
Logging with Castle.Facilities.Logging and log4net
Among other things, it describes how to write your own custom Castle Windsor logging facility to be injected by Castle Windsor.
Create your own facility for Common.Logging, checkout how it's done for the existing Logging Facility in Windsor. Common.Logging probably has a logger factory you would utilize in the facility to create a logger.
Or you could save yourself the work and just use Castle's ILogger with the Logging facility: Windsor will inject ILogger instances in your classes for you. Works with log4net and NLog v2.