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: Appender to run at a Schedule Time
Prev Next
You are not authorized to post a reply.

Author Messages
HemantJPatel

09/30/2008 5:29 PM  


Hi,

I need to run the smtp appender at a specified interval of time.
Any ideas how I can do this to that the appender will run at specific
intervals and send all the buffered messages.

Any pointers will be helpful.
Thanks in advance.

Thanks,
Hemant

Ron Grabowski

10/02/2008 11:17 PM  

Use a Timer?

// untested
public class AutoFlushSmtpAppender : SmtpAppender
{
    private System.Timers.Timer timer;

    private int interval;

    /// <summary>
    /// Flush interval in milliseconds.
    /// </summary>
    public int Interval
    {
        get { return interval; }
        set { interval = value; }
    }

    public override void ActivateOptions()
    {
        base.ActivateOptions();
        ErrorHandler = new StopTimerErrorHandler(this, ErrorHandler);

        timer = new Timer(Interval);
        timer.Elapsed += delegate { Flush(); };
        timer.Start();
    }

    protected override void OnClose()
    {
        stopTimer();
        base.OnClose();
    }

    private void stopTimer()
    {
        if (timer.Enabled)
        {
            timer.Enabled = false;
            timer.Stop();
        }
    }

    class StopTimerErrorHandler : IErrorHandler
    {
        private readonly AutoFlushSmtpAppender appender;
        private readonly IErrorHandler wrapped;

        public StopTimerErrorHandler(AutoFlushSmtpAppender appender, IErrorHandler wrapped)
        {
            this.appender = appender;
            this.wrapped = wrapped;
        }

        public void Error(string message, Exception e, ErrorCode errorCode)
        {
            appender.stopTimer();
            wrapped.Error(message, e, errorCode);
        }

        public void Error(string message, Exception e)
        {
            appender.stopTimer();
            wrapped.Error(message, e);
        }

        public void Error(string message)
        {
            appender.stopTimer();
            wrapped.Error(message);
        }
    }
}

You are not authorized to post a reply.
Forums > Log4Net > Log4Net Mail archive > Appender to run at a Schedule Time



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