Hi:
zli,
Walden H. Leverich,
Erich Eichinger:
Thanks a lot.
I think my question is a very common scenaio .
I also read some mails in log4net maillist about
ThreadContext.Properties.
But I can't get the answer.
I want to use HttpContext to instead of System.thread in my project
when HttpContext.Current is not null.
I want to modify the source code of log4net.
Can it work well?
Erich:
Because mail system blocked .zip file. Would you like change the XXX.zip
to XXX.txt?
Thank you very much.
-----Original Message-----
From: Erich Eichinger [mailto:[EMAIL PROTECTED]
Sent: 2007年9月27日 1:45
To: Log4NET User
Subject: RE: Can I use static logger and ThreadContext.Properties in asp.net
project?
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:[EMAIL PROTECTED]
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
[EMAIL PROTECTED]
<BLOCKED::blocked::http://www.techsoftinc.com/> http://www.TechSoftInc.com
Quiquid latine dictum sit altum viditur.
(Whatever is said in Latin seems profound.)