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.
| 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. |
|
|
|
ActiveForums 3.7
|