Log4Net filters “OR”

你离开我真会死。 提交于 2019-12-23 10:29:38

问题


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>

I really don't want to write my own filter and would prefer to accomplish this with the normal Log4Net filters. Is this possible?


回答1:


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>

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 :)



来源:https://stackoverflow.com/questions/1245960/log4net-filters-or

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!