我想配置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
如何配置的附加器,使我得到一个电子邮件与最后10行,如果WARN或更高的发生,但以其他方式忽略了缓冲区?