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:

 http://www.nlog-project.org/target.ASPNetBufferingWrapper.html

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 <[EMAIL PROTECTED]>
To: [email protected]
Sent: Tuesday, November 27, 2007 9:37:07 AM
Subject: batching log entries until exception



Hello,

I searched the list for this information, but I think my use case is a
 bit
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.
  In
our case, this would be an ASP.NET request.  We want to hold onto these
 logs
in memory until either the request completes or an exception occurs.
  We
want to output all the batched logs if an exception occurs, and discard
 the
ones that don't pass the normal filters if there were no errors.  

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

--
David Bicking
-- 
View this message in context:
 
http://www.nabble.com/batching-log-entries-until-exception-tf4882083.html#a13971789
Sent from the Log4net - Users mailing list archive at Nabble.com.




Reply via email to