Log4Net "OR" Filters

Is it possible to create a filter, for example, a PropertyFilter, which is neutral (and passed to the next filter in the chain) if one or the other value matches? Sort of:

<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 rather do it with the usual Log4Net filters. Is it possible?

+5
source share
1 answer

You could develop such a filter yourself by running the FilterSkeleton subclass.

But instead of creating a specialized filter like this, I suggest you rather implement a more general filter that can be configured to contain a set of filters and apply an operator to them. The configuration might 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 recommend that you send it to the log4net project. This would be useful for the general public :)

+4
source

Source: https://habr.com/ru/post/904567/


All Articles