我正在尝试配置 log4net SmtpAppender,以便仅在达到某个日志级别时才收到电子邮件,但包括所有级别的最后 10 行。这是我的配置:
<appender name="EmailAppender" type="SmtpSubjectLayoutAppender">
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="WARN"/>
</evaluator>
<bufferSize value="10" />
<lossy value="false" />
...
</appender>
我正在使用以下代码进行练习:
for (var i = 1; i <= 30; i++)
{
logger.Info("This is just a test message " + i);
}
logger.Error("Error message");
问题是我最终收到了 3 封电子邮件,其中 2 封包含所有INFO
日志记录,另外一封包含在以下内容之前发生的最后几行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
如何配置附加程序,以便在发生 WARN 或更高时收到一封包含最后 10 行的电子邮件,否则忽略缓冲区?