tags:

views:

10

answers:

1

I would like to filter my log4net output by filters comprised of (threshold AND pattern). So I want to allow logs with pattern "x" only if they are level "ERROR" (or higher), and allow logs with pattern "y" only if they are level "INFO" (or higher). Can I do this in one appender, or do I need two appenders, each with its own pattern filter and threshold?

A: 

Log4net allows you to chain filters but this is works only as "OR". I think you could also make it do an "AND" operation but not really what you want. I would write my own filter that checks if the level and the pattern match. Then chain two instances of this filter to make it check the first condition and the second condition ("OR" operation). Do not forget the DenyAllFilter at the end.

I wrote a custom filter once, maybe this is helpful for creating your filter.

Two appenders might be a workaround, but if you want to log to a file you have locking issues which can be resolved (with performance penalty).

Stefan Egli