Log4Net过滤器“OR” [英] Log4Net filters "OR"
问题描述
是否可以创建一个过滤器,例如PropertyFilter是中性的(并且传递给链中的下一个过滤器),如果一个或另一个值匹配?像:
Is it possible to make a filter, for example a PropertyFilter that is neutral (and passed to next filter in the chain) if either one or another value matches? Something like:
<filter type="log4net.Filter.PropertyFilter">
<Key value="myProperty" />
<StringsToMatch Operator="OR">
<Match>value1</Match>
<Match>value2</Match>
</StringsToMatch>
</filter>
我真的不想写我自己的过滤器,并希望用普通的Log4Net过滤器。这是可能吗?
I really don't want to write my own filter and would prefer to accomplish this with the normal Log4Net filters. Is this possible?
推荐答案
你可以自己通过继承 FilterSkeleton 。
You could certainly develop such a filter yourself by subclassing FilterSkeleton.
但是,我建议您不要像这样创建一个特殊的过滤器,而是实现一个更通用的过滤器,它可以配置为包含过滤器集合,并对其应用操作符。配置可以看起来像这样:
But instead of making a specialized filter like this I suggest you rather implement a more generic filter that could be configured to contain a collection of filters and apply the Operator over those. The config could look something like this:
<filter type="CompositeFilter">
<operator value="Or" />
<filters>
<filter type="log4net.Filter.PropertyFilter">
<stringToMatch value="value1" />
</filter>
<filter type="log4net.Filter.PropertyFilter">
<stringToMatch value="value2" />
</filter>
</filters>
</filter>
如果你做这样的过滤器,我鼓励你提交它到log4net项目。这对一般公众当然是有用的:)
If you make such a filter I encourage you to submit it to the log4net project. It would certainly be useful for the general public :)
这篇关于Log4Net过滤器“OR”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!