5

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?

Mike Gates
  • 1,874
  • 3
  • 21
  • 40

1 Answers1

5

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

Peter Lillevold
  • 33,668
  • 7
  • 97
  • 131