This is an extended SmtpAppender that has its threshold property set to Error
and should only ever process one message.
// untested
public class SendOnceErrorSmtpAppender : SmtpAppender
{
private bool sendOnce = true;
public override void ActivateOptions()
{
Threshold =
LogManager.GetRepository().LevelMap.LookupWithDefault(Level.Error);
}
protected override bool PreAppendCheck()
{
if (sendOnce && base.PreAppendCheck())
{
sendOnce = false;
}
return sendOnce;
}
}
----- Original Message ----
From: Marvin <[EMAIL PROTECTED]>
To: Log4NET User <[email protected]>
Sent: Saturday, July 14, 2007 6:18:36 AM
Subject: Re: Making SMTPAppender Send Exactly One Email
Sanders, Brian wrote:
> You could create a flag and initialize it to false. Then, if an error
> occurs, set it to true and check it at the end of the run. If it's true,
> then email the log file.
So there's no way to do this with SMTPAppender itself?
Then I'll rather use a FileAppender and send the error log using a
second program.
/Marvin