logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Francine Taylor" <Francine.Tay...@genesis-fs.com>
Subject RE: Set & Get MemoryAppender from a named Logger
Date Fri, 31 Oct 2008 17:54:44 GMT
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

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:lukas.schluechter@roche.com] 
Sent: Friday, October 31, 2008 6:15 AM
To: log4net-user@logging.apache.org
Subject: Set & Get MemoryAppender from a named Logger

Following statements are not supportet...

// Getting a Specific Appender from a specific logger
 IAppender myapp =

// attaching a specific Appender to a specific logger

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:
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

View raw message