Friday, May 18, 2012
 
The best way to analyze your logs! Minimize
 Log4Net Mail archive   

The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.

Subject: Elapsed time evaluator
Prev Next
You are not authorized to post a reply.

Author Messages
Parrish, Ken

12/13/2007 4:35 PM  

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.

Ron Grabowski

12/14/2007 6:38 AM  
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; }
    }
}
Parrish, Ken

12/17/2007 4:04 PM  

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.

 

You are not authorized to post a reply.
Forums > Log4Net > Log4Net Mail archive > Elapsed time evaluator



ActiveForums 3.7

 

 

 

 

 

 

 

 

Log4Net Dashboard

Log analysis and monitoring made easy!

Log4Net Dashboard is a log viewer that can read log statements from a variety of logging output targets.

You can download a free developer version.

  

Check it out!

On the demonstration site you can try it  with live data.demo.l4ndash.com - Try Log4Net Dashboard with live data

The mail archive is a copy of all the mail sent to the mail address: log4net-user@logging.apache.org, organized as a forum.

If you would like to participate in the mail list, send a mail to log4net-user-subscribe@logging.apache.org.

More information about the mailing list is available on: http://logging.apache.org/log4net/support.html

 

A complete topic list is available and can be viewed here (warning, it takes some time to load)

 

Copyright 2005-2008 by FaktNet AS Terms Of Use Privacy Statement