Monday, May 21, 2012
 
The best way to analyze your logs! Minimize
 Log4Net Mail archive   

The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.

Subject: Set & Get MemoryAppender from a named Logger
Prev Next
You are not authorized to post a reply.

Author Messages
schlud

10/31/2008 2:14 PM  


Following statements are not supportet...

// Getting a Specific Appender from a specific logger
 IAppender myapp =
LogManager.GetLogger("MyNamedLogger1").GetAppender("MyNamedAppender");

// attaching a specific Appender to a specific logger
 LogManager.GetLogger("MyNamedLogger1").SetAppender("MyNamedAppender");


How can I access a desired Appender of a known logger directly, without
iterating over all Appenders and query thier names?


How can I attach a specific Appender to an Specific Logger ?
Thanks in Advance


--
View this message in context: http://www.nabble.com/Set---Get-MemoryAppender-from-a-named-Logger-tp20265747p20265747.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Francine Taylor

10/31/2008 6:54 PM  

Try this:

Hierarchy hier = (Hierarchy)LogManager.GetRepository();
Logger mylog = (Logger)hier.GetLogger("MyNamedLogger1");
IAppender myap = mylog.GetAppender("MyNamedAppender");

There is only one problem with this, and that is that if the logger
doesn't exist, log4net will create it.  myap will still return as null,
because the newly created logger won't have that appender, but then
you've got a junk logger in your repository.

You can prevent that by replacing your GetLogger() call with a looping
search:

Hierarchy hier = (Hierarchy)LogManager.GetRepository();
foreach (ILogger l in hier.GetCurrentLoggers()) {
    if (l.Name.Equals(loggerName)) {
        IAppender myap = l.GetAppender("MyNamedAppender");
        if (myap != null) {
            // do stuff
        }
    }
}

...but then you're back to looping.

schlud

11/04/2008 2:27 PM  


Hello Francine

Thanks, that was what I had searched for!

For setting an appender, i would make something like this:

Hierarchy hier = (Hierarchy)LogManager.GetRepository();
        Logger mylog = (Logger)hier.GetLogger("MyNamedLogger1");
        IAppender memap = new MemoryAppender();
        memap.Name = "blabla";
        mylog.AddAppender(memap);

Have a great time!
bye

You are not authorized to post a reply.
Forums > Log4Net > Log4Net Mail archive > Set & Get MemoryAppender from a named Logger



ActiveForums 3.7

 

 

 

 

 

 

 

 

Log4Net Dashboard

Log analysis and monitoring made easy!

Log4Net Dashboard is a log viewer that can read log statements from a variety of logging output targets.

You can download a free developer version.

  

Check it out!

On the demonstration site you can try it  with live data.demo.l4ndash.com - Try Log4Net Dashboard with live data

The mail archive is a copy of all the mail sent to the mail address: log4net-user@logging.apache.org, organized as a forum.

If you would like to participate in the mail list, send a mail to log4net-user-subscribe@logging.apache.org.

More information about the mailing list is available on: http://logging.apache.org/log4net/support.html

 

A complete topic list is available and can be viewed here (warning, it takes some time to load)

 

Copyright 2005-2008 by FaktNet AS Terms Of Use Privacy Statement