当SmtpAppender的bufferSize大于1时,将忽略Log4Net LevelEvaluator [英] Log4Net LevelEvaluator Ignored when bufferSize greater than 1 for SmtpAppender

查看:117
本文介绍了当SmtpAppender的bufferSize大于1时,将忽略Log4Net LevelEvaluator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用RollingLogFileAppender和SmtpAppender配置了log4net,目的是将DEBUG级别记录到RollingLogFileAppender并将FATAL记录到SmtpAppender:

I have configured log4net with a RollingLogFileAppender and a SmtpAppender, with the intention of logging the DEBUG level to the RollingLogFileAppender and FATAL only to the SmtpAppender:

<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
  <to value="test@test.com" />
  <from value="test@test.com" />
  <subject value="Fatal Error" />
  <smtpHost value="smtp.test.com" />
  <SMTPPort value="366"/>
  <Username value="test@test.com"/>
  <Password value="password"/>      
  <bufferSize value="1" />
  <lossy value="true" />
  <evaluator type="log4net.Core.LevelEvaluator">
    <threshold value="FATAL"/>
  </evaluator>      
  <layout type="log4net.Layout.PatternLayout">
  <conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline"                             />
  </layout>
</appender>

<root>
  <level value="DEBUG" />
  <appender-ref ref="RollingLogFileAppender" />
  <appender-ref ref="SmtpAppender" />
</root>

这很好,直到我增加bufferSize为止.当我这样做时,所有级别都通过电子邮件发送,log4net.Core.LevelEvaluator似乎被忽略了.我也尝试过使用LevelRangeFilter和LevelMatchFilter,但是配置这些后,我似乎根本没有收到电子邮件.

This works perfectly until I increase the bufferSize. When I do this, all levels are sent via email and the log4net.Core.LevelEvaluator seems to be ignored. I have also tried using LevelRangeFilter and LevelMatchFilter but with these configured I seem to get no emails at all.

推荐答案

不会忽略该评估程序,但是它不会执行您期望的操作:您的设置指示附加程序将所有日志消息放在缓冲区中并仅发送电子邮件当记录具有致命级别的消息时.如果缓冲区已满,则会丢弃最旧的消息(这是有损设置;如果没有此设置,则缓冲区已满时您也会收到一封电子邮件).

The evaluator is not ignored, but it does not do what you expect: Your settings instruct the appender to put all log messages on a buffer and send an email only when a message with level FATAL is logged. If the buffer is full then the oldest messages are discarded (that is the lossy setting; without it you would also get an email as soon as the buffer is full).

如果要过滤消息,则需要使用过滤器.例如这样的

If you want to filter the messages then you need to use a filter. For instance like this:

<filter type="log4net.Filter.LevelMatchFilter">
   <acceptOnMatch value="true" />
   <levelToMatch  value="FATAL" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />

我不确定我是否会考虑这样的邮件附加程序,因为如果我的应用程序有问题需要以FATAL级别对其进行记录,我想立即得到通知.

I am not sure though if I would consider my mail appender like this since I would want to get notified immediately if my application has a problem that it needs to log it with level FATAL.

这篇关于当SmtpAppender的bufferSize大于1时,将忽略Log4Net LevelEvaluator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆