Use Logger in Handler. Does Agatha suppor this?

24 views
Skip to first unread message

shapper

unread,
Mar 9, 2012, 8:50:16 AM3/9/12
to agath...@googlegroups.com
Hello,

I am using Agatha with Common.Logging and NLog.
It is working great in handle exceptions on the handlers!

I need to log some info inside one handler. Something like:

  this.Log(Type.Info, "The newsletter was @ 13:45");

Is it possible to access the Logger from the handler?

Or do I need to inject the logger in the handler?

Thank You,
Miguel

Davy Brion

unread,
Mar 9, 2012, 10:16:46 AM3/9/12
to agath...@googlegroups.com
Nope, you'll have to inject it

shapper

unread,
Mar 10, 2012, 6:24:08 AM3/10/12
to agath...@googlegroups.com
 I ended up using the following and it works:

      ILog log = LogManager.Adapter.GetLogger(this.GetType());
      log.Info("Test");

Not sure if it is better to inject it ... Is it? How do you usually do it?

Thank You,
Miguel

Davy Brion

unread,
Mar 11, 2012, 1:48:15 PM3/11/12
to agath...@googlegroups.com
I used to create a logger by default through the LogManager in a base requesthandler type which was available through a Logger property to all deriving handlers.

Unless you specifically want to assert on logged messages during tests, there's nothing wrong with that IMO.
Reply all
Reply to author
Forward
0 new messages