[prev in list] [next in list] [prev in thread] [next in thread]
List: log4net-user
Subject: RE: Can I use static logger and ThreadContext.Properties in asp.net project?
From: "Erich Eichinger" <E.Eichinger () diamonddogs ! cc>
Date: 2007-09-30 15:44:54
Message-ID: 5819CEE5BB511B4285A1F4BC147C537751D885 () maildog ! office ! dd ! loc
[Download RAW message or body]
Hi,
> I want to use HttpContext to instead of System.thread
that's exactly what the code I provided is doing.
> I want to modify the source code of log4net.
that's possible, but I don't recommend it. I've gone through maintaining my own \
versions of 2 frameworks for a while - it's a nightmare always merging changes if \
bugs get fixed or new features are added. A much better way is to create your \
solution and contribute it to the project. In this particular case feel free to take \
my code, update it for log4net 1.2.10 and contribute it to the log4net project. I \
guess a couple of people might be thankful (including myself)
> Because mail system blocked .zip file. Would you like change the XXX.zip to \
> XXX.txt?
It's only your own client software blocking the attachment. You can download the \
attachment e.g. from apache's mailing archives here: \
http://mail-archives.apache.org/mod_mbox/logging-log4net-user/200709.mbox/browser \
<http://mail-archives.apache.org/mod_mbox/logging-log4net-user/200709.mbox/browser> \
cheers,
Erich
________________________________
From: Chen, Xuguang [mailto:Xuguang.Chen@cn.fid-intl.com]
Sent: Sun 2007-09-30 03:07
To: 'Log4NET User'
Subject: RE: Can I use static logger and ThreadContext.Properties in asp.net project?
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:E.Eichinger@diamonddogs.cc]
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: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
Quiquid latine dictum sit altum viditur.
(Whatever is said in Latin seems profound.)
[Attachment #3 (text/html)]
<HTML dir=ltr><HEAD><TITLE>Message</TITLE>
<META http-equiv=Content-Type content="text/html; charset=unicode">
<META content="MSHTML 6.00.6000.16525" name=GENERATOR>
<STYLE>font-face {
font-family: Wingdings;
}
font-face {
font-family: Wingdings;
}
font-face {
font-family: Calibri;
}
font-face {
font-family: Verdana;
}
P.MsoNormal {
FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman","serif"
}
LI.MsoNormal {
FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman","serif"
}
DIV.MsoNormal {
FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman","serif"
}
A:link {
COLOR: blue; TEXT-DECORATION: underline;}
SPAN.MsoHyperlink {
COLOR: blue; TEXT-DECORATION: underline;}
A:visited {
COLOR: purple; TEXT-DECORATION: underline;}
SPAN.MsoHyperlinkFollowed {
COLOR: purple; TEXT-DECORATION: underline;}
P {
FONT-SIZE: 12pt; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; FONT-FAMILY: "Times New \
Roman","serif";} SPAN.EmailStyle18 {
COLOR: #1f497d; FONT-FAMILY: "Calibri","sans-serif";}
.MsoChpDefault {
FONT-SIZE: 10pt;}
DIV.Section1 {
page: Section1
}
OL {
MARGIN-BOTTOM: 0in
}
UL {
MARGIN-BOTTOM: 0in
}
</STYLE>
</HEAD>
<BODY lang=EN-US vLink=purple link=blue>
<DIV id=idOWAReplyText80241 dir=ltr>
<DIV dir=ltr><FONT face=Arial color=#000000 size=2>Hi,</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Tahoma color=#000080 size=2>> I want to use \
HttpContext to instead of System.thread</FONT></DIV> <DIV dir=ltr><FONT face=Arial \
size=2>that's exactly what the code I provided is doing.</FONT></DIV> <DIV \
dir=ltr><FONT face=Arial size=2></FONT> </DIV> <DIV dir=ltr><FONT face=Arial \
size=2>> <FONT face=Tahoma color=#000080>I want to modify \
the source code of log4net.</FONT></FONT></DIV> <DIV dir=ltr><FONT face=Arial \
color=#000000 size=2>that's possible, but I don't recommend it. I've gone through \
maintaining my own versions of 2 frameworks for a while - it's a nightmare always \
merging changes if bugs get fixed or new features are added. A much better way is to \
create your solution and contribute it to the project.</FONT></DIV> <DIV \
dir=ltr><FONT face=Arial color=#000000 size=2>In this particular case feel free \
to take my code, update it for log4net 1.2.10 and contribute it to the log4net \
project. I guess a couple of people might be thankful (including myself)</FONT></DIV> \
<DIV dir=ltr><FONT color=#000080 size=2></FONT> </DIV> <DIV dir=ltr><FONT \
size=2><FONT face=Tahoma>> <FONT color=#0000ff>Because mail system blocked .zip \
file. Would you like change the XXX.zip to XXX.txt?</FONT></FONT></FONT></DIV> <DIV \
dir=ltr><FONT face=Arial size=2><FONT color=#000000>It's only your own client \
software blocking the attachment. You can download the attachment e.g. from apache's \
mailing archives here: </FONT><A \
href="http://mail-archives.apache.org/mod_mbox/logging-log4net-user/200709.mbox/browser"><FONT \
color=#000000>http://mail-archives.apache.org/mod_mbox/logging-log4net-user/200709.mbox/browser</FONT></A></FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial color=#000000 size=2>cheers,</FONT></DIV>
<DIV dir=ltr><FONT face=Arial color=#000000 size=2>Erich</FONT></DIV></DIV>
<DIV dir=ltr><BR>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Chen, Xuguang \
[mailto:Xuguang.Chen@cn.fid-intl.com]<BR><B>Sent:</B> Sun 2007-09-30 \
03:07<BR><B>To:</B> 'Log4NET User'<BR><B>Subject:</B> RE: Can I use static logger and \
ThreadContext.Properties in asp.net project?<BR></FONT><BR></DIV> <DIV>
<DIV><SPAN class=677565200-30092007><FONT face=宋体 size=2><FONT \
color=#000080>Hi:</FONT></FONT></SPAN></DIV> <DIV><SPAN \
class=677565200-30092007><FONT face=宋体 size=2><FONT \
color=#000080>zli,</FONT></FONT></SPAN></DIV> <DIV><SPAN \
class=677565200-30092007><FONT face=宋体 size=2><FONT color=#000080><FONT \
face=Tahoma>Walden H. Leverich,</FONT></FONT></FONT></SPAN></DIV> <DIV><SPAN \
class=677565200-30092007><FONT face=宋体 size=2><FONT color=#000080><FONT \
face=Tahoma>Erich Eichinger:</FONT></FONT></FONT></SPAN></DIV> <DIV><SPAN \
class=677565200-30092007><FONT face=Tahoma size=2></FONT></SPAN> </DIV> \
<DIV><SPAN class=677565200-30092007><FONT face=宋体 color=#000080 \
size=2> Thanks a lot.</FONT></SPAN></DIV> <DIV><SPAN \
class=677565200-30092007><FONT face=宋体 color=#000080 \
size=2></FONT></SPAN> </DIV> <DIV><SPAN class=677565200-30092007><FONT \
face=宋体 color=#000080 size=2> I think my question is \
a very common scenaio .</FONT></SPAN></DIV> <DIV><SPAN class=677565200-30092007><FONT \
face=宋体 size=2><FONT color=#000080> I also read some \
mails in log4net maillist about <FONT \
face=Tahoma>ThreadContext.Properties.</FONT></FONT></FONT></SPAN></DIV> <DIV><SPAN \
class=677565200-30092007><FONT face=Tahoma color=#000080 \
size=2> But I can't get the \
answer.</FONT></SPAN></DIV> <DIV><SPAN class=677565200-30092007><FONT face=Tahoma \
color=#000080 size=2> I want to use HttpContext \
to instead of System.thread in my project when HttpContext.Current is not \
null.</FONT></SPAN></DIV> <DIV><SPAN class=677565200-30092007><FONT face=Tahoma \
color=#000080 size=2> I want \
to modify the source code of log4net.</FONT></SPAN></DIV> <DIV><SPAN \
class=677565200-30092007><FONT face=Tahoma color=#000080 \
size=2> Can it work \
well?</FONT></SPAN></DIV> <DIV><SPAN class=677565200-30092007><FONT \
color=#000080></FONT></SPAN> </DIV> <DIV><SPAN class=677565200-30092007><FONT \
color=#0000ff size=2>Erich:</FONT></SPAN></DIV> <DIV><SPAN \
class=677565200-30092007><FONT color=#0000ff size=2> \
</FONT></SPAN></DIV> <DIV><SPAN class=677565200-30092007><FONT color=#0000ff \
size=2> Because mail system blocked .zip file. Would you like \
change the XXX.zip to XXX.txt?</FONT></SPAN></DIV> <DIV><SPAN \
class=677565200-30092007><FONT color=#0000ff size=2> Thank you very \
much.</FONT></SPAN></DIV> <DIV><SPAN class=677565200-30092007><FONT face=Tahoma \
size=2></FONT></SPAN> </DIV> <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV></DIV>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><FONT face=Tahoma \
size=2>-----Original Message-----<BR><B>From:</B> Erich Eichinger \
[mailto:E.Eichinger@diamonddogs.cc] <BR><B>Sent:</B> 2007年9月27日 \
1:45<BR><B>To:</B> Log4NET User<BR><B>Subject:</B> RE: Can I use static logger and \
ThreadContext.Properties in asp.net project?<BR><BR></FONT></DIV> <DIV dir=ltr \
align=left><SPAN class=013072717-26092007><FONT face=Arial color=#0000ff \
size=2>Hi,</FONT></SPAN></DIV> <DIV dir=ltr align=left><SPAN \
class=013072717-26092007><FONT face=Arial color=#0000ff \
size=2></FONT></SPAN> </DIV> <DIV dir=ltr align=left><SPAN \
class=013072717-26092007><FONT face=Arial color=#0000ff size=2>as Walden states: most \
of the time it will work, but there's no guarantee.</FONT></SPAN></DIV> <DIV dir=ltr \
align=left><SPAN class=013072717-26092007><FONT face=Arial color=#0000ff \
size=2></FONT></SPAN> </DIV> <DIV dir=ltr align=left><SPAN \
class=013072717-26092007><FONT face=Arial color=#0000ff size=2>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".</FONT></SPAN></DIV> <DIV dir=ltr \
align=left><SPAN class=013072717-26092007><FONT face=Arial color=#0000ff \
size=2></FONT></SPAN> </DIV> <DIV dir=ltr align=left><SPAN \
class=013072717-26092007><FONT face=Arial color=#0000ff size=2>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</FONT></SPAN></DIV> <DIV \
dir=ltr align=left><SPAN class=013072717-26092007><FONT face=Arial color=#0000ff \
size=2></FONT></SPAN> </DIV> <DIV dir=ltr align=left><SPAN \
class=013072717-26092007><FONT face=Arial color=#0000ff size=2>hope this \
helps,</FONT></SPAN></DIV> <DIV dir=ltr align=left><SPAN \
class=013072717-26092007><FONT face=Arial color=#0000ff \
size=2>Erich</FONT></SPAN></DIV><BR> <BLOCKQUOTE dir=ltr style="PADDING-LEFT: 5px; \
MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px"> <DIV \
class=OutlookMessageHeader lang=de dir=ltr align=left> <HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Walden H. Leverich \
[mailto:WaldenL@TechSoftInc.com] <BR><B>Sent:</B> Tuesday, September 25, 2007 9:13 \
PM<BR><B>To:</B> Log4NET User<BR><B>Subject:</B> RE: Can I use static logger and \
ThreadContext.Properties in asp.net project?<BR></FONT><BR></DIV> <DIV></DIV>
<DIV class=Section1>
<P class=MsoNormal><SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: \
'Calibri','sans-serif'">Xuguang,</SPAN></P> <P class=MsoNormal><SPAN \
style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: \
'Calibri','sans-serif'"></SPAN> </P> <P class=MsoNormal><SPAN style="FONT-SIZE: \
11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'">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. \
</SPAN></P> <P class=MsoNormal><SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; \
FONT-FAMILY: 'Calibri','sans-serif'"></SPAN> </P> <P class=MsoNormal><SPAN \
style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'">In \
short, set the properties at the start of the request (in global.asax for example) \
and you’re fine <B>for that request</B>, but not across requests.</SPAN></P> <P \
class=MsoNormal><SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: \
'Calibri','sans-serif'"></SPAN> </P> <P class=MsoNormal><SPAN style="FONT-SIZE: \
11pt; COLOR: #1f497d; FONT-FAMILY: 'Calibri','sans-serif'">-Walden</SPAN></P> <P \
class=MsoNormal><SPAN style="FONT-SIZE: 11pt; COLOR: #1f497d; FONT-FAMILY: \
'Calibri','sans-serif'"></SPAN> </P> <DIV>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt; COLOR: #0080ff; FONT-FAMILY: \
'Verdana','sans-serif'">-- </SPAN><SPAN style="COLOR: #1f497d"></SPAN></P> <P \
class=MsoNormal><SPAN style="FONT-SIZE: 10pt; COLOR: #0080ff; FONT-FAMILY: \
'Verdana','sans-serif'">Walden H Leverich III<BR>Tech Software<BR>(516) 627-3800 \
x3051</SPAN><SPAN style="COLOR: #1f497d"></SPAN></P></DIV> <P class=MsoNormal><SPAN \
style="FONT-SIZE: 10pt; COLOR: #0080ff; FONT-FAMILY: \
'Verdana','sans-serif'">WaldenL@TechSoftInc.com<BR></SPAN><SPAN style="COLOR: \
#1f497d"><A title="blocked::http://www.techsoftinc.com/ http://www.techsoftinc.com/" \
href=""><SPAN style="FONT-SIZE: 10pt; COLOR: #0080ff; FONT-FAMILY: \
'Verdana','sans-serif'">http://www.TechSoftInc.com</SPAN></A><BR><BR></SPAN><SPAN \
style="FONT-SIZE: 10pt; COLOR: #0080ff; FONT-FAMILY: 'Verdana','sans-serif'">Quiquid \
latine dictum sit altum viditur.<BR>(Whatever is said in Latin seems \
profound.)</SPAN> </P> <P \
class=MsoNormal> </P></DIV></BLOCKQUOTE></BLOCKQUOTE></DIV></BODY></HTML>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic