Return-Path: Delivered-To: apmail-logging-log4net-user-archive@www.apache.org Received: (qmail 73420 invoked from network); 1 Sep 2010 17:37:42 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 1 Sep 2010 17:37:42 -0000 Received: (qmail 84219 invoked by uid 500); 1 Sep 2010 17:37:41 -0000 Delivered-To: apmail-logging-log4net-user-archive@logging.apache.org Received: (qmail 84036 invoked by uid 500); 1 Sep 2010 17:37:41 -0000 Mailing-List: contact log4net-user-help@logging.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Log4NET User" List-Id: Delivered-To: mailing list log4net-user@logging.apache.org Received: (qmail 84028 invoked by uid 99); 1 Sep 2010 17:37:40 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Sep 2010 17:37:40 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [64.201.43.87] (HELO hobbes.BURLINGTON.IVARA.COM) (64.201.43.87) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Sep 2010 17:37:32 +0000 Received: from hobbes.BURLINGTON.IVARA.COM ([192.168.0.9]) by hobbes.BURLINGTON.IVARA.COM ([192.168.0.9]) with mapi; Wed, 1 Sep 2010 13:41:37 -0400 From: Rob Prouse To: Log4NET User Date: Wed, 1 Sep 2010 13:41:36 -0400 Subject: RE: Custom Properties in an ASP.Net Web Application Thread-Topic: Custom Properties in an ASP.Net Web Application Thread-Index: ActJ5W0OBxtUmSM3SwuXjGHcmXAZVQACGJ6QAAAYOuAAAu0SIA== Message-ID: References: <038C9B245F74BC4B869B757F143086520682409941@biz-email> <038C9B245F74BC4B869B757F143086520682409944@biz-email> In-Reply-To: <038C9B245F74BC4B869B757F143086520682409944@biz-email> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: multipart/alternative; boundary="_000_D0A5983C38E59B4CA97DC4D4285159DE3AD0D817C7hobbesBURLING_" MIME-Version: 1.0 X-Virus-Checked: Checked by ClamAV on apache.org --_000_D0A5983C38E59B4CA97DC4D4285159DE3AD0D817C7hobbesBURLING_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable I took a quick look at the code and as far as I can see, the ThreadContext = is taken out of the logging event when formatting the message which happens= when it is being written. Therefore, I believe that if you use any appende= r deriving from the BufferingSkeletonAppender, then the ThreadContext will = be wrong because the writing of the message happens on a different thread. = So, I don't think you can use the ThreadContext. I assume you want to use properties so that you can have them as separate c= olumns in the DB, otherwise you could just insert the values into the messa= ge. If that is the case, then the only solution I can think of is to downlo= ad the source, copy the code from the ADO appender and create your own that= does not derive from the buffering appender. Or, you could look at NLog and see if it meets your needs. Rob From: Gagne, Chris [mailto:cgagne@ivey.uwo.ca] Sent: Wednesday, September 01, 2010 12:01 PM To: 'Log4NET User' Subject: RE: Custom Properties in an ASP.Net Web Application Yeah we're using the log4net.Appender.AdoNetAppender. From: Rob Prouse [mailto:Rob.Prouse@Ivara.com] Sent: Wednesday, September 01, 2010 11:59 AM To: Log4NET User Subject: RE: Custom Properties in an ASP.Net Web Application For the common log appenders, the log is output synchronously with the log = message, so it should be on the same thread, so it shouldn't be a problem. = I am not sure of the behavior when you use an asynchronous appender (like t= he ADO appender), but it should be pulling the context out before it goes a= synchronous. If it doesn't, then that would be a bug in log4net, but I woul= d need to look at the code. What appender are you using? From: Gagne, Chris [mailto:cgagne@ivey.uwo.ca] Sent: Wednesday, September 01, 2010 11:03 AM To: Log4NET User Subject: Custom Properties in an ASP.Net Web Application Here's our situation... We're adding debug messages to an ASP.Net web application that allows our u= sers to apply for a job online. We have a custom properties and database f= ields created named JobPostingId and MemberId. Here's a small code snippet= of our logging. ILog logger =3D LogManager.GetLogger(CONST_JOBPOSTINGS); if (logger.IsDebugEnabled) { log4net.ThreadContext.Properties[CONST_JOBPOSTINGID] =3D Jo= bPostingId; log4net.ThreadContext.Properties[CONST_MEMBERID] =3D MemberId; logger.Debug(message); } We've noticed very inconsistent values for our custom properties. I suspec= t it has something to do with the context belonging to a thread and that sa= me thread being reused by different web requests, therefore different users= . Does anyone have suggestions for me on how I can capture user specific data= into custom properties? Any thoughts or suggestions would be greatly appr= eciated. --_000_D0A5983C38E59B4CA97DC4D4285159DE3AD0D817C7hobbesBURLING_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

I took a quick look at t= he code and as far as I can see, the ThreadContext is taken out of the logging even= t when formatting the message which happens when it is being written. Therefo= re, I believe that if you use any appender deriving from the BufferingSkeletonAppender, then the ThreadContext will be wrong because the= writing of the message happens on a different thread. So, I don’t think you c= an use the ThreadContext.

 =

I assume you want to use properties so that you can have them as separate columns in the DB, otherwi= se you could just insert the values into the message. If that is the case, the= n the only solution I can think of is to download the source, copy the code f= rom the ADO appender and create your own that does not derive from the bufferin= g appender.

 =

Or, you could look at NL= og and see if it meets your needs.

 =

Rob

 =

From: Gagne, Chris [mailto:cgagne@ivey.uwo.ca]
Sent: Wednesday, September 01, 2010 12:01 PM
To: 'Log4NET User'
Subject: RE: Custom Properties in an ASP.Net Web Application

 

Yeah we’re using t= he log4net.Appender.AdoNetAppender.

 =

From: Rob Prouse [mailto:Rob.Prouse@Ivara.com]
Sent: Wednesday, September 01, 2010 11:59 AM
To: Log4NET User
Subject: RE: Custom Properties in an ASP.Net Web Application

 

For the common log appen= ders, the log is output synchronously with the log message, so it should be on th= e same thread, so it shouldn’t be a problem. I am not sure of the behav= ior when you use an asynchronous appender (like the ADO appender), but it shoul= d be pulling the context out before it goes asynchronous. If it doesn’t, t= hen that would be a bug in log4net, but I would need to look at the code.<= /o:p>

 =

What appender are you us= ing?

 =

From: Gagne, Chris [mailto:cgagne@ivey.uwo.ca]
Sent: Wednesday, September 01, 2010 11:03 AM
To: Log4NET User
Subject: Custom Properties in an ASP.Net Web Application<= /span>

 

Here’s our situation…

 

We’re adding debug messages to an ASP.Net web application that allows our users to apply for a job online.  We have = a custom properties and database fields created named JobPostingId and MemberId.  Here’s a small code snippet of our logging.

 

ILog logger =3D LogManager.GetLogger(CONST_JOBPOSTINGS= );

 

if (logger.IsDebugEnabled)

{

         =        log4net.ThreadContext.Properties[CONST_JOBPOSTINGID] =3D JobPostingId;=

log4net.ThreadContext.Prope= rties[CONST_MEMBERID] =3D MemberId;

         =        logger.Debug(message);

}

 

We’ve noticed very inconsistent values for our c= ustom properties.  I suspect it has something to do with the context belongi= ng to a thread and that same thread being reused by different web requests, therefore different users.

 

Does anyone have suggestions for me on how I can captu= re user specific data into custom properties?  Any thoughts or suggestion= s would be greatly appreciated.

--_000_D0A5983C38E59B4CA97DC4D4285159DE3AD0D817C7hobbesBURLING_--