为什么Log4Net筛选器会收到评估器阈值之外的消息? [英] Why do Log4Net Filters Receive Messages Outside of the Evaluator Threshold?

查看:91
本文介绍了为什么Log4Net筛选器会收到评估器阈值之外的消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的log4net配置是这样的:

My log4net config is like this:

    <appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
      <to value="xxx" />
      <from value="xxx" />
      ...
      <evaluator type="log4net.Core.LevelEvaluator">
        <threshold value="ERROR"/>
      </evaluator>
      <filter type="MyApp.Logging.EmailLogThrottler">
      </filter>
    </appender>

如果我在MyApp.Logging.EmailLogThrottler类中设置了一个断点,则看到它正在接收要过滤的INFO消息. EmailLogThrottler相当昂贵,因此按照评估者阈值,我只希望它接收ERROR消息.这可能吗?

If I set a breakpoint in my MyApp.Logging.EmailLogThrottler class, I see it is receiving INFO messages to filter. The EmailLogThrottler is fairly expensive so I only want it to receive ERROR messages, as per the evaluator threshold. Is this possible?

第二个问题-似乎首先应用了过滤器,然后应用了评估器阈值(对我来说这很直观).这个假设正确吗?

Secondary question - it seems that filters are applied first and then evaluator thresholds (which is counter intuitive to me). Is this assumption correct?

推荐答案

对于第一个问题,直接在附加器上设置阈值 以获得最佳性能:

For your first question, set the threshold directly on the appender for best performance:

<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
  <to value="xxx" />
  <from value="xxx" />
  ...
  <threshold value="ERROR"/>

请参见

一个消息是否比另一个消息早丢弃?

Does one discard messages sooner than the other?

答案:

阈值与评估者不同.

The threshold is different to the evaluator.

阈值在AppenderSkeleton中实现,因此 几乎所有附加程序都支持.这只是一个简单的测试 用于忽略级别低于阈值的日志记录事件. 尽早检查阈值,并且非常简单的测试 表演者.

The threshold is implemented in the AppenderSkeleton and therefore supported by almost all appenders. It is just a simple test that is used to ignore logging events that have a level below the threshold. The threshold is checked early and as a simple test is very performant.

该帖子继续讲到有关评估程序的信息,该评估程序并非旨在过滤邮件,而是触发发送缓冲的邮件:

The post goes on to say this about the Evaluator, which is not intended to filter messages, but instead to trigger sending the buffered messages:

Evaluator是可插拔对象,由 BufferingAppenderSkeleton确定是否不应记录日志事件 被缓冲,而是立即写入/发送.如果评估者 认为该事件很重要,则该事件的全部内容 当前缓冲区将与事件一起发送. 评估者 不像阈值或过滤器那样起作用,因为它不 放弃事件.

The Evaluator is a pluggable object that is used by the BufferingAppenderSkeleton to determine if a logging event should not be buffered, but instead written/sent immediately. If the Evaluator decides that the event is important then the whole contents of the current buffer will be sent along with the event. The evaluator does not function like the threshold or a filter in that it does not discard events.

在过滤器上有这个说法

过滤器具有很大的灵活性,因为多个过滤器可以 链接在一起以提供对事件的细粒度控制 输出.因此,它们的成本也更高 性能方面,链中的每个过滤器都是一个对象,并被要求 确定正确的行动方案.

Filters have a great deal of flexibility because multiple filters can be chained together to provide fine grained control over the events that are output. Because of this they also have a higher cost in terms of performance, each filter in the chain is an object and is asked to decide on the correct course of action.

在简单的情况下 阈值过滤阈值属性应在 偏好过滤器.

In the simple case of the threshold filtering the Threshold property should be used in preference to a filter.

这篇关于为什么Log4Net筛选器会收到评估器阈值之外的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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