Log4Net configuration - LevelMatchFilter

iffi picture iffi · Oct 11, 2011 · Viewed 16.1k times · Source

As there are following levels in log4net

  • ALL
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • FATAL
  • OFF

Can anyone please tell me in log4net how can I log only INFO & ERROR or DEBUG & ERROR? What I mean here is be able to log two different levels which are not in sequence?

I can't do if I use following because warning messages will be logged as well which I don't want:

<filter type="log4net.Filter.LevelRangeFilter">
    <acceptOnMatch value="true" />
    <levelMin value="INFO" />
    <levelMax value="ERROR" />
</filter>

Answer

iffi picture iffi · Oct 17, 2011

Use LevelMatchFilter in conjunction with DenyAllFilter:

<filter type="log4net.Filter.LevelMatchFilter">
  <acceptOnMatch value="true" />
  <levelToMatch  value="INFO" />
</filter>
<filter type="log4net.Filter.LevelMatchFilter">
  <acceptOnMatch value="true" />
  <levelToMatch  value="ERROR" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />