Log4net
  1. Log4net
  2. LOG4NET-137

log4net.Filter.LevelMatchFilter does not work anymore

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 1.2.10
    • Fix Version/s: 1.2.11
    • Component/s: Other
    • Labels:
      None

      Description

      The following log4net configuration used to filter only FATAL messages to the event log. In version 1.2.10, this will send all messages to the EventLog. If I remove the LevelMatchFilter and replace it with a LevelRangeFilter which has a minLevel set to FATAL, the filtering occurs properly.

      <log4net>
      <root>
      <level value="Info" />
      <appender-ref ref="All" />
      <appender-ref ref="Error" />
      <appender-ref ref="EventLog" />
      <!-- <appender-ref ref="Console" /-->
      </root>
      <appender name="EventLog" type="log4net.Appender.EventLogAppender" >
      <param name="ApplicationName" value="SQLNotifyApp" />
      <layout type="log4net.Layout.PatternLayout">
      <param name="ConversionPattern" value="%d

      {yyyyMMdd:HHmmss.fffff}

      [%t] %-5p %c %x - %m%n" />
      </layout>
      <filter type="log4net.Filter.LevelMatchFilter">
      <param name="LevelToMatch" value="FATAL" />
      </filter>
      </appender>
      <appender name="Error" type="log4net.Appender.RollingFileAppender">
      <file value="SQLNotifyApp_Error.log" />
      <appendToFile value="true" />
      <rollingStyle value="Date" />
      <datePattern value="yyyyMMdd" />
      <filter type="log4net.Filter.LevelMatchFilter">
      <param name="LevelToMatch" value="ERROR" />
      </filter>
      <layout type="log4net.Layout.PatternLayout" >
      <param name="conversionPattern" value="%d

      {yyyyMMdd:HHmmss.fffff}

      [%t] %-5p %c %x - %m%n" />
      </layout>
      </appender>

      <appender name="All" type="log4net.Appender.RollingFileAppender">
      <file value="SQLNotifyApp_All.log" />
      <appendToFile value="true" />
      <rollingStyle value="Date" />
      <datePattern value="yyyyMMdd" />
      <layout type="log4net.Layout.PatternLayout" >
      <param name="conversionPattern" value="%d

      {yyyyMMdd:HHmmss.fffff}

      [%t] %-5p %c %x - %m%n" />
      </layout>
      </appender>
      <appender name="Console" type="log4net.Appender.ConsoleAppender">
      <layout type="log4net.Layout.PatternLayout" >
      <param name="conversionPattern" value="%d

      {yyyyMMdd:HHmmss.fffff}

      [%t] %-5p %c %x - %m%n" />
      </layout>
      </appender>
      </log4net>

        Activity

        Benjamin Peikes created issue -
        Hide
        Ron Grabowski added a comment -

        A better place for general questions about log4net is the mailing lists.

        I suspect you need to add a DenyAllFilter to the end of the filter chain for your EventLog appender:

        <filter type="log4net.Filter.LevelMatchFilter">
        <levelToMatch value="FATAL" />
        </filter>
        <filter type="log4net.Filter.DenyAllFilter" />

        A more efficient way of specifying that you only way FATAL messages is to set the threshold on the appender:

        <appender name="EventLog" type="log4net.Appender.EventLogAppender" >
        <applicationName value="SQLNotifyApp" />
        <layout type="log4net.Layout.PatternLayout">
        <conversionPattern" value="%d

        {yyyyMMdd:HHmmss.fffff}

        [%t] %-5p %c %x - %m%n" />
        </layout>
        <threshold value="FATAL" />
        </appender>

        The threshold property is checked before the appender starts rendering the message so non-FATAL messages will be discarded sooner.

        Show
        Ron Grabowski added a comment - A better place for general questions about log4net is the mailing lists. I suspect you need to add a DenyAllFilter to the end of the filter chain for your EventLog appender: <filter type="log4net.Filter.LevelMatchFilter"> <levelToMatch value="FATAL" /> </filter> <filter type="log4net.Filter.DenyAllFilter" /> A more efficient way of specifying that you only way FATAL messages is to set the threshold on the appender: <appender name="EventLog" type="log4net.Appender.EventLogAppender" > <applicationName value="SQLNotifyApp" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern" value="%d {yyyyMMdd:HHmmss.fffff} [%t] %-5p %c %x - %m%n" /> </layout> <threshold value="FATAL" /> </appender> The threshold property is checked before the appender starts rendering the message so non-FATAL messages will be discarded sooner.
        Ron Grabowski made changes -
        Field Original Value New Value
        Fix Version/s 1.2.11 [ 12310980 ]
        Assignee Ron Grabowski [ ron ]
        Hide
        Ron Grabowski added a comment -

        Adding a DenyAllFilter should fix this issue.

        Show
        Ron Grabowski added a comment - Adding a DenyAllFilter should fix this issue.
        Ron Grabowski made changes -
        Resolution Invalid [ 6 ]
        Status Open [ 1 ] Resolved [ 5 ]

          People

          • Assignee:
            Ron Grabowski
            Reporter:
            Benjamin Peikes
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development