You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Ping Xie <px...@caci.com> on 2005/06/01 18:20:57 UTC
Log4net threadsafe storage
Hi,
I'm writing an audit log utility for our product using log4net. There are
custom fields need to be output. I used MDC to set those fields every time
before calling ILog.Debut() (or Error(), Fatal()...). The following is the
sample code
// Set output fields
log4net.MDC.Set("theUser", strUser);
log4net.MDC.Set("sessionid", strSession);
log4net.MDC.Set("machine", strClientMachine);
//Output data
log.Warn(message);
Because during the same session (thread) the above data is the same. I'm
wondering if there is threadsafe storage in log4net so that the setting
output fields block is only called once. The audit log utility is used
enormously in our product. Therefore performance is very critical.
I'd appreciate it if any one can show me a better solution or point me to
related documents. By the way, I'm using log4net 1.2 beta8. We can upgrade
it if needed.
Thank you in advance.
Ping Xie
CACI
4831 Walden Lane
Lanham, MD 20706
pxie@caci.com
(301) 306-8200 - Main
(301) 306-2829 - Direct
Re: Log4net threadsafe storage
Posted by Ron Grabowski <ro...@yahoo.com>.
log4net 1.2.9 beta has a ThreadContext context:
http://logging.apache.org/log4net/release/manual/contexts.html
Is something not working with the way you're doing it now or are you
just inquiring if there is a more effecient way?
--- Ping Xie <px...@caci.com> wrote:
> Hi,
>
> I'm writing an audit log utility for our product using log4net. There
> are
> custom fields need to be output. I used MDC to set those fields every
> time
> before calling ILog.Debut() (or Error(), Fatal()...). The following
> is the
> sample code
>
> // Set output fields
> log4net.MDC.Set("theUser", strUser);
> log4net.MDC.Set("sessionid", strSession);
> log4net.MDC.Set("machine", strClientMachine);
>
> //Output data
> log.Warn(message);
>
> Because during the same session (thread) the above data is the same.
> I'm
> wondering if there is threadsafe storage in log4net so that the
> setting
> output fields block is only called once. The audit log utility is
> used
> enormously in our product. Therefore performance is very critical.
>
> I'd appreciate it if any one can show me a better solution or point
> me to
> related documents. By the way, I'm using log4net 1.2 beta8. We can
> upgrade
> it if needed.
>
> Thank you in advance.
>
> Ping Xie
>
> CACI
> 4831 Walden Lane
> Lanham, MD 20706
> pxie@caci.com
> (301) 306-8200 - Main
> (301) 306-2829 - Direct
>