I'm trying to configure a log4net SmtpAppender so that I only get an e-mail if a certain log level is hit, but with the last 10 lines from all levels included. This is my config:
<appender name="EmailAppender" type="SmtpSubjectLayoutAppender">
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="WARN"/>
</evaluator>
<bufferSize value="10" />
<lossy value="false" />
...
</appender>
I'm exercising it with this code:
for (var i = 1; i <= 30; i++)
{
logger.Info("This is just a test message " + i);
}
logger.Error("Error message");
The problem is that I end up getting 3 e-mails, 2 with all the INFO
logging and one that has the last few lines that occurred before the ERROR
:
[2012-07-27 18:59:55.657][INFO ][Chase][tid=14972] This is just a test message 23
[2012-07-27 18:59:55.659][INFO ][Chase][tid=14972] This is just a test message 24
[2012-07-27 18:59:55.661][INFO ][Chase][tid=14972] This is just a test message 25
[2012-07-27 18:59:55.662][INFO ][Chase][tid=14972] This is just a test message 26
[2012-07-27 18:59:55.664][INFO ][Chase][tid=14972] This is just a test message 27
[2012-07-27 18:59:55.666][INFO ][Chase][tid=14972] This is just a test message 28
[2012-07-27 18:59:55.667][INFO ][Chase][tid=14972] This is just a test message 29
[2012-07-27 18:59:55.670][INFO ][Chase][tid=14972] This is just a test message 30
[2012-07-27 18:59:55.671][ERROR][Chase][tid=14972] Error message
How do I configure the appender so that I get an e-mail with the last 10 lines if WARN or higher occurred, but to ignore the buffer otherwise?