logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erich Eichinger" <E.Eichin...@diamonddogs.cc>
Subject RE: Can I use static logger and ThreadContext.Properties in asp.net project?
Date Wed, 26 Sep 2007 17:44:57 GMT
Hi,
 
as Walden states: most of the time it will work, but there's no guarantee.
 
a few years ago (log4net 1.2.9) I wrote an extension "LogicalWebContext" to workaround this
missing feature. Instead of a threadstatic, it stores properties into HttpContext.Items. The
extension consists of a HttpModule and a new Appender, "WebContextAwareForwardingAppender".
 
note, that this code has been written for net 1.1 and log4net 1.2.9. I expect that there are
some changes necessary to make it run with log4net 1.2.10 and net 2.0
 
hope this helps,
Erich


________________________________

	From: Walden H. Leverich [mailto:WaldenL@TechSoftInc.com] 
	Sent: Tuesday, September 25, 2007 9:13 PM
	To: Log4NET User
	Subject: RE: Can I use static logger and ThreadContext.Properties in asp.net project?
	
	

	Xuguang,

	 

	Assuming you're not using async-pages, a single request will be processed by a single thread,
so you can set the properties at request-start and read them later in the process w/out concern.
However, note I said "single-request." You cannot use the thread context like session state,
there is no guarantee that you'll end up on the same thread next time you request a page from
the server, and there's no guarantee that a single thread won't handle multiple requests.
In fact, I can promise that a single thread will process multiple requests, that's how you
get performance. 

	 

	In short, set the properties at the start of the request (in global.asax for example) and
you're fine for that request, but not across requests.

	 

	-Walden

	 

	-- 

	Walden H Leverich III
	Tech Software
	(516) 627-3800 x3051

	WaldenL@TechSoftInc.com
	http://www.TechSoftInc.com <BLOCKED::blocked::http://www.techsoftinc.com/> 
	
	Quiquid latine dictum sit altum viditur.
	(Whatever is said in Latin seems profound.) 

	 


Mime
View raw message