logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ron Grabowski <rongrabow...@yahoo.com>
Subject Re: batching log entries until exception
Date Tue, 27 Nov 2007 17:40:21 GMT
You could store a list or CyclicBuffer in the HttpContext then write an HttpModule that flushes
the events when appropriate. If you use a CyclicBuffer you can set it so the message count
doesn't exceed a certain number. I recall there being some discussion about writing code that
would capture the last 500 DEBUG messages and only send them to an appender if an exception
occurred. If no exception occurred, the messages would be destroyed when the HttpContext is
disposed. NLog has such a target:


One implementation might call for an appender to be aware that it will be used in the context
of an ASP.Net website and will eventually forward its contents to another appender:

 public class HttpContextBufferingForwardingAppender : BufferingForwardingAppender, IHttpModule
   // TODO: buffer items in HttpContext, flush when the HttpApplication's Error event is raised

Writing log events to an appender is usually a slower process than generating them so there
shouldn't be much overhead with capturing messages then ignoring them.

----- Original Message ----
From: David Bicking <David.Bicking@thehartford.com>
To: log4net-user@logging.apache.org
Sent: Tuesday, November 27, 2007 9:37:07 AM
Subject: batching log entries until exception


I searched the list for this information, but I think my use case is a
obscure.  I am researching Log4Net as a possible plug-in logger for our
software.  We would like to have or create an unusual feature.  

We would like to collect log entries in memory during a discrete scope.
our case, this would be an ASP.NET request.  We want to hold onto these
in memory until either the request completes or an exception occurs.
want to output all the batched logs if an exception occurs, and discard
ones that don't pass the normal filters if there were no errors.  

Has anyone done something like this with Log4Net?  Do you have
on how I might implement this using Log4Net?

David Bicking
View this message in context:
Sent from the Log4net - Users mailing list archive at Nabble.com.

View raw message