7 Aug 10:10
ASP.NET, AdoNetAppender and deferred property execution
From: Jerry Shea <jerry.shea <at> gmail.com>
Subject: ASP.NET, AdoNetAppender and deferred property execution
Newsgroups: gmane.comp.log.log4net.user
Date: 2008-08-07 08:12:10 GMT
Subject: ASP.NET, AdoNetAppender and deferred property execution
Newsgroups: gmane.comp.log.log4net.user
Date: 2008-08-07 08:12:10 GMT
Hi Everyone,
I am seeing a problem here which I believe is due to deferred property execution. I have a ClientLogger which gets a property value from the HttpSession as below.
public class ClientLogger {
public override string ToString() {
string retval = "-";
if (HttpContext.Current != null && HttpContext.Current.Session != null && HttpContext.Current.Session["client"] != null)
retval = (string)HttpContext.Current.Session["client"];
return retval;
}
}
My log4net is configured with an AdoNetAppender which of course is a BufferingAppender.
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="100" />
<connectionType value="blah..." />
<connectionString value="blah..." />
<commandText value="INSERT INTO blah..." />
... ...
<parameter>
<parameterName value=" <at> client" />
<dbType value="String" />
<size value="100" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{client}" />
</layout>
</parameter>
... ...
</appender>
The problem is, when I look in my database I and compare the rows there with what I see in my log file (generated from RollingFileAppender) I can see that the property values for "client" do not match. I presume this is because my ClientLogger is not being called until the AdoNetAppender's buffer is flushed.
Can anyone confirm if my diagnosis is correct, and, if so, is there a way to have these properties evaluated when the log statement is executed, rather than at flush time?
Thanks, Jerry
I am seeing a problem here which I believe is due to deferred property execution. I have a ClientLogger which gets a property value from the HttpSession as below.
public class ClientLogger {
public override string ToString() {
string retval = "-";
if (HttpContext.Current != null && HttpContext.Current.Session != null && HttpContext.Current.Session["client"] != null)
retval = (string)HttpContext.Current.Session["client"];
return retval;
}
}
My log4net is configured with an AdoNetAppender which of course is a BufferingAppender.
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="100" />
<connectionType value="blah..." />
<connectionString value="blah..." />
<commandText value="INSERT INTO blah..." />
... ...
<parameter>
<parameterName value=" <at> client" />
<dbType value="String" />
<size value="100" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{client}" />
</layout>
</parameter>
... ...
</appender>
The problem is, when I look in my database I and compare the rows there with what I see in my log file (generated from RollingFileAppender) I can see that the property values for "client" do not match. I presume this is because my ClientLogger is not being called until the AdoNetAppender's buffer is flushed.
Can anyone confirm if my diagnosis is correct, and, if so, is there a way to have these properties evaluated when the log statement is executed, rather than at flush time?
Thanks, Jerry
RSS Feed