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.
-----Original Message-----
From: schlud [mailto:[EMAIL PROTECTED]
Sent: Friday, October 31, 2008 6:15 AM
To: [email protected]
Subject: Set & Get MemoryAppender from a named Logger
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-tp202
65747p20265747.html
Sent from the Log4net - Users mailing list archive at Nabble.com.
==========================================
NOTICE: The contents of this e-mail message and any attachments are intended
solely for the addressee(s) named in this message. This communication is
intended to be and to remain confidential. If you are not the intended
recipient of this message, or if this message has been addressed to you in
error, please immediately alert the sender by reply e-mail and then delete this
message and its attachments. Do not deliver, distribute or copy this message
and/or any attachments and if you are not the intended recipient, do not
disclose the contents or take any action in reliance upon the information
contained in this communication or any attachments.
Thank you