Hi Dominik,

Thanks for your reply.
I am trying to do option 2. I would like to buffer the logs for a particular 
request and only output them if an exception occurs. 
However, I would only want to output logs related to that request, so in my 
head I need a buffer per request but perhaps there is a more performant way to 
handle this in log4net?

Thanks
Joe

-----Original Message-----
From: Dominik Psenner [mailto:[email protected]] 
Sent: 08 August 2012 15:53
To: 'Log4NET User'
Subject: RE: Lossy logging on a per user basis for a high traffic website

Hi Joe,

> I would need to buffer huge volumes of other users messages in order 
> to be

> confident that the user who is in an exceptional state still had all 
> their

> messages in the buffer.

My approach would be as simple as this pseudo-code:

public abstract class YourFilter : FilterSkeleton {
   private List<string> usersInError = new List<string>();

   public override bool Decide(LoggingEvent loggingEvent) {
      // check if the logging event satisfies a error condition
      if(IsConditionMet(loggingEvent)) {
         usersInError.Add(GetGroup(loggingEvent));
      }
      // make sure the event is logged
      if(usersInError.Contains(GetGroup(loggingEvent))) {
         if(IsCancelConditionmet(loggingEvent)) {
           usersInError.Remove(GetGroup(loggingEvent));
         }
         return true;
      }
      return false;
   }

   private abstract bool IsConditionMet(LoggingEvent loggingEvent);
   private abstract bool IsCancelConditionMet(LoggingEvent loggingEvent);
   private abstract string GetGroup(LoggingEvent loggingEvent); }

This discards messages until a specific condition is met and then starts 
logging all future events for the same group of LoggingEvents until a specific 
cancel condition is met.

The grouping function could return the username and thus effectively log only 
messages for a user in exceptional state.

> Instead, I think I need some sort of buffer per request that the 
> appender uses when the ERROR condition is satisfied, however I am 
> unsure if log4net's architecture would allow me to do this?

Log4net dispatches logging events to an appender that claims to be in charge 
and it is left to the appender how the logging event is treated. The most 
common operations are to:

  * serialize (to a file, to a database, ..)
  * discard
  * buffer (i.e. to minimize overheads like file open/close/lock operations)
  * relay to other appenders

Just to make sure I understood Your situation, please tell me. Are you:

 1] Trying to log future events after a specific event has been detected?
 2] Trying to log past events that have already happened before a specific 
event has been detected?

Cheers,
Dominik



Reply via email to