Sunday, November 23, 2008
 
The best way to analyze your logs! Minimize
 Log4Net Mail archive   

The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.

Subject: ASP.NET, AdoNetAppender and deferred property execution
Prev Next
You are not authorized to post a reply.

Author Messages
Jerry Shea

08/07/2008 10:12 AM  
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="@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




Jerry Shea

08/07/2008 12:42 PM  
Yes I have confirmed that this is the case - when the AdoNetAppender's buffer flushes then and only then are the properties evaluated.


Jerry Shea

08/11/2008 6:30 AM  
Hi Everyone,

Apologies for sending multiple messages about this, but I guess my initial question was buried at the bottom of email#1.

Does anyone have a idea as to how I can force properties to be resolved at log time rather than flush time?

Thx, Jerry
Ron Grabowski

08/12/2008 5:44 AM  
Have you tried setting the Fix property to All or Partial?

 http://logging.apache.org/log4net/release/sdk/log4net.Appender.BufferingAppenderSkeleton.Fix.html
 
Jerry Shea

08/22/2008 1:43 PM  
Ron,

thanks very much for the suggestion - the Fix property did the job after I worked out (from the log4net source) that my custom properties had to implement IFixingRequired. Once I did that I then found http://piers7.blogspot.com/2007/07/log4net-in-aspnet-redux-implement.html which describes exactly my issue.

Can I suggest some additions to the doco? I've created an issue in JIRA with a patch - https://issues.apache.org/jira/browse/LOG4NET-170 - would appreciate any feedback.

Cheers
You are not authorized to post a reply.
Forums > Log4Net > Log4Net Mail archive > ASP.NET, AdoNetAppender and deferred property execution



ActiveForums 3.7

 

 

 

 

 

 

 

 

Log4Net Dashboard

Log analysis and monitoring made easy!

Log4Net Dashboard is a log viewer that can read log statements from a variety of logging output targets.

You can download a free developer version.

  

Check it out!

On the demonstration site you can try it  with live data.demo.l4ndash.com - Try Log4Net Dashboard with live data

The mail archive is a copy of all the mail sent to the mail address: log4net-user@logging.apache.org, organized as a forum.

If you would like to participate in the mail list, send a mail to log4net-user-subscribe@logging.apache.org.

More information about the mailing list is available on: http://logging.apache.org/log4net/support.html

 

A complete topic list is available and can be viewed here (warning, it takes some time to load)

 

Copyright 2005-2008 by FaktNet AS Terms Of Use Privacy Statement