Castle Windsor Logging Facility - named loggers

263 views
Skip to first unread message

Sosh

unread,
Oct 16, 2009, 3:51:30 AM10/16/09
to Castle Project Users
Hi,

I've set up the Windsor logging facility, and have it working with
log4net. However, I can't figure out how to specify which named
logger the messages should go to - how do I do this? (At the moment
they seem to just go to root)

Thanks,

S

Ken Egozi

unread,
Oct 16, 2009, 5:20:37 AM10/16/09
to castle-pro...@googlegroups.com
do not contaier.Resolve<ILogger>().
the whole idea is to have windsor deal with it - by having a component dependent on ILogger, and have Windsor resolve it.

Say:

namespace A
{
   public class B
   {
      ILogger logger;
      public B(ILogger logger) { this.logger = logger };
   }
}

Assuming you Resolve<A.B>()  (or otherwise have B as a dependency on somehting else), the logger instance will have the name A.B

if you *have* to get hold of a logger instance directly (say on the application's entry point), you should resolve the ILoggerFactory, and have it create the proper named instance:

var logger = container.Resolve<ILoggerFactory>().Create(typeof(A.B));



I have a couple of blog posts on that exact topic, awaiting to be finalized and published (no time though)

--
Ken Egozi.
http://www.kenegozi.com/blog
http://www.delver.com
http://www.musicglue.com
http://www.castleproject.org
http://www.idcc.co.il - הכנס הקהילתי הראשון למפתחי דוטנט - בואו בהמוניכם

Sosh

unread,
Oct 16, 2009, 6:19:54 AM10/16/09
to Castle Project Users
Hi Ken,

I'm not using container.Resolve. I'm using the built in logging
facility in Windsor. So in my container initialisation I have
something like:

container.AddFacility("logging", new LoggingFacility
(LoggerImplementation.Log4net));

And then in my consuming classed, I just have:

public ILogger Logger

which windsor injects into.

This is working fine, but as far as I can see I have no control over
which *named* logger this is using.

Thanks,

S

On Oct 16, 11:20 am, Ken Egozi <egoz...@gmail.com> wrote:
> do not contaier.Resolve<ILogger>().the whole idea is to have windsor deal
> Ken Egozi.http://www.kenegozi.com/bloghttp://www.delver.comhttp://www.musicglue.comhttp://www.castleproject.orghttp://www.idcc.co.il- הכנס הקהילתי הראשון למפתחי דוטנט - בואו בהמוניכם

Ken Egozi

unread,
Oct 16, 2009, 6:22:29 AM10/16/09
to castle-pro...@googlegroups.com
the name is the fully qualified classname.
If you want something different, then you should create an ILoggerFactory that will do what you want it to do.
take a peek into the existing Log4Net integration's ILoggerFactory implementation to get started
http://www.idcc.co.il - הכנס הקהילתי הראשון למפתחי דוטנט - בואו בהמוניכם
Reply all
Reply to author
Forward
0 new messages