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