views:

230

answers:

1

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?

+2  A: 

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
Yeah, I was hoping someone else had done this already. I'm suprised such a mature logging engine would not have this capability already in the trunk.
Mike Gates