3

I've just started using log4net and have some issues with filtering using strings.

I'm trying to remove EPiServer specific logging in my log4net log file as I am not interested in it.

I have the following log4net configuration for an appender:

        <filter type="log4net.Filter.LevelRangeFilter">
           <levelMin value="DEBUG" />
        </filter>

        <filter type="log4net.Filter.StringMatchFilter">
            <stringToMatch value="EPiServer" />
            <acceptOnMatch value="false" />
        </filter>
        <filter type="log4net.Filter.DenyAllFilter" />

I only have one root logger. This config does not stop the EPiServer logging.

What am I doing wrong?

peter3
  • 1,074
  • 13
  • 22

2 Answers2

3

Try changing your StringMatchFilter to a LoggerMatchFilter

<filter type="log4net.Filter.LoggerMatchFilter">
  <loggerToMatch value="EPiServer" />
  <acceptOnMatch value="false" />  
</filter>

A StringMatchFilter filters on the content of the log message, where a LoggerMatch filters on the Logger's class Name or partial Namespace

tompipe
  • 949
  • 6
  • 8
  • I only use the root logger and I guess EPiServer does as well, so maybe that's why I can't make this work for me? – peter3 Feb 14 '13 at 09:18
  • Just to clarify: I tried to use the filter as suggested, but still EpiServer entries show up in the log file. – peter3 Feb 14 '13 at 11:44
  • 1
    The filter element needs to go within the appender you've chosen, not within the root element. – tompipe Feb 18 '13 at 09:53
  • 2
    also move the levelrangefilter to the end of the chain, otherwise all DEBUG messages are already passed through – Wouter Sep 23 '13 at 14:55
3

You should remove the line

<filter type="log4net.Filter.DenyAllFilter" />

From the docs:

You can add this filter to the end of a filter chain to switch from the default "accept all unless instructed otherwise" filtering behavior to a "deny all unless instructed otherwise" behavior.

Which effectively reverses the logic to deny all messages unless explicitly whitelisted inside a <filter> using <acceptOnMatch value="true" />

bottlenecked
  • 2,079
  • 2
  • 21
  • 32