3
votes

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?

2

2 Answers

3
votes

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" />

2
votes

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