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.
| 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. |
|
|
|
ActiveForums 3.7
|