ThreadContext and a filter was perfect for me :)

Thanks allot!

Best Regards
*Morten Andersen*
Developer
Vianett AS <http://www.vianett.no/> | [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> | Office: +47 69 20 69 74 <callto://+4769206974> | Skype: mortander <callto://mortander>



Nicko Cadell wrote:
The NDC is metadata attached to the logging event. It is not used in
routing the event to an appender. The NDC is a string which is built by
concatenating the names of the nested contexts.

The best you can do is route all logging events to the appender and then
use a filter on the appender to only allow the events with the correct
NDC data to be logged. You may be able to use the
log4net.Filter.NdcFilter to do this, but you may be better off writing a
custom filter.

In your case it sounds like you are not actually using the NDC to build
up a nested context (think call stack for log message), so you may want
to just set a thread local context property instead. See the
log4net.ThreadContext class for details.

Nicko

-----Original Message-----
From: Morten Andersen [mailto:[EMAIL PROTECTED] Sent: 25 March 2006 10:25
To: Log4NET User
Subject: Re: Question about NDC and appenders

I forgot to includethis in my last mail.

This is what I have today:
<appender name="Protocol_P1" type="WebHandlerRollingFileAppender"/>

        <logger name="Protocol_P1_Receiver">
            <appender-ref ref="Protocol_P1"/>
        </logger>

        <logger name="Protocol_P1_Handler">
            <appender-ref ref="Protocol_P1"/>
        </logger>


Here I reference two loggers to the appender. What I need to do is to reference a NDC contexts (Protocol_P1_Receiver and Protocol_P1_Handler) to the Protocol_P1 appender.

- Morten

Ron Grabowski wrote:
I don't understand the question. By specific NDC context do
you mean
you're using nested using() statements?

using(ThreadContext.Stacks["NDC"].Push("first push")) { using(ThreadContext.Stacks["NDC"].Push("second push")) { log.Info("This log message has two NDC entires"); }
log.Info("This
log message has one NDC entry"); }

--- Morten Andersen <[EMAIL PROTECTED]> wrote:

Can I configure log4net to route messages from a specific
NDC context
to a appender?

- Morten


Reply via email to