3
votes

The following class is registered in the Windsor Castle container:

namespace MyNamespace
{
    class Foo : IFoo
    {
        public Foo(ILog log)
        {
             _log = log;
        }
        ...
    }
}

ILog is a log4net logger, currently registered like this:

Component.For<ILog>().UseFactoryMethod(
    () => LogManager.GetLogger(Assembly.GetCallingAssembly().FullName));

I would like to create a logger named like the calling type (in this case "MyNamespace.Foo") rather than like the calling assembly. Is there a way to do it, except for using reflection to play with stack frames?

1
have you looked at the logging facility in castle?Can Gencer
See stackoverflow.com/a/13388644/25702 for possible answer to thisDavid Gardiner

1 Answers

3
votes

The castle windsor logging facility does what you want. It has integration with log4net or NLog already (see: how to set up logging facility).

If you are curious still, you can examine the source code to see how exactly it can be done. Take a look at the log4net Integration source and the logging facility source and especially at the LoggerResolver class (which does the name resolving).