Ron,

 

Thank you so much for the help.  This looks like it will do the job.  I will be 
a few days before I can work this up, but will let you know how it goes.

 

Thanks,

 

Ken Parrish

Gomez, Inc.

 

________________________________

From: Ron Grabowski [mailto:[EMAIL PROTECTED] 
Sent: Friday, December 14, 2007 12:38 AM
To: Log4NET User
Subject: Re: Elapsed time evaluator

 

This might work:

// untested
public class IntervalEvalulator : ITriggeringEventEvaluator
{
    private DateTime lastTriggeringEvent = DateTime.MinValue;
    private int intervalSeconds = 60;

    public bool IsTriggeringEvent(LoggingEvent loggingEvent)
    {
        if (lastTriggeringEvent == DateTime.MinValue)
        {
            lastTriggeringEvent = loggingEvent.TimeStamp;
            return false;
        }
        else
        {
            TimeSpan diff = loggingEvent.TimeStamp - lastTriggeringEvent;
            lastTriggeringEvent = loggingEvent.TimeStamp;
            return (diff.TotalSeconds > intervalSeconds);
        }
    }

    public int IntervalSeconds
    {
        get { return intervalSeconds; }
        set { intervalSeconds = value; }
    }
}

You could also create an appender that flushes at a predefined interval:

// untested
public class FlushIntervalSmtpAppender : SmtpAppender
{
    private Timer timer;
    private int intervalSeconds;

    public override void ActivateOptions()
    {
        if (IntervalSeconds > 0)
        {
            timer = new Timer(IntervalSeconds);
            timer.Elapsed += delegate { if (BufferSize > 0) Flush(true); };
            LogManager.GetRepository().ShutdownEvent += delegate { 
timer.Stop(); };
            timer.Start();
        }

        base.ActivateOptions();
    }

    public double IntervalSeconds
    {
        get { return intervalSeconds; }
        set { intervalSeconds = value; }
    }
}

----- Original Message ----
From: "Parrish, Ken" <[EMAIL PROTECTED]>
To: [email protected]
Sent: Thursday, December 13, 2007 10:35:24 AM
Subject: Elapsed time evaluator

As a follow up to my question about metering SMTP messages, I was thinking 
about the possibility of creating a custom Evaluator that works on elapsed 
time.  Whereas the LevelEvaluator triggers on a particular level of message, 
this evaluator would trigger on a specified elapsed time.

 

In the case of and SMTP appender, an ‘ElapsedTimeEvaluator’ would wait for a 
specified period of time before sending an e-mail with all the messages in it’s 
buffer.

 

Has anyone attempted to create a custom evaluator?  Has anyone ever see a 
similar custom implementation for log4net?  Ideas, comments?

 

Thanks,

 

Ken Parrish

Gomez, Inc.

 

Reply via email to