开发者

Logging level isn't working

开发者 https://www.devze.com 2023-01-24 09:30 出处:网络
I have configured my application to use log4net as follows: <log4net> <appender name=\"SQL_Comandos\" type=\"log4net.Appender.AdoNetAppender\">

I have configured my application to use log4net as follows:

<log4net>
    <appender name="SQL_Comandos" type="log4net.Appender.AdoNetAppender">
      <bufferSize value="100" />
      <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <connectionString value="X" />
      <commandText value="INSERT INTO X ([Date],[Thread],[Level],[Logger],[Message],[Exception],[Usuario]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception, @usuario)" />
      <parameter>
        <parameterName value="@log_date" />
        <dbType value="DateTime" />
        <layout type="log4net.Layout.RawTimeStampLayout" />
      </parameter>
      <parameter>
        <parameterName value="@thread" />
        <dbType value="String" />
        <size value="255" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%thread" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@log_level" />
        <dbType value="String" />
        <size value="50" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%level" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@logger" />
        <dbType value="String" />
        <size value="255" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%logger" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@message" />
        <dbType value="String" />
        <size value="4000" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%message" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@exception" />
        <dbType value="String" />
        <size value="2000" />
        <layout type="log4net.Layout.ExceptionLayout" />
      </parameter>
      <parameter>
        <parameterName value="@usuario" />
        <dbType value="String" />
        <size value="50" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%X{usuario}" />
        </layout>
      </parameter>
    </appender>
    <appender name="SQL_Hibernate" type="log4net.Appender.AdoNetAppender">
      <bufferSize value="100" />
      <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <connectionString value="X" />
      <commandText value="INSERT INTO X ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" />
      <parameter>
        <parameterName value="@log_date" />
        <dbType value="DateTime" />
        <layout type="log4net.Layout.RawTimeStampLayout" />
      </parameter>
      <parameter>
        <parameterName value="@thread" />
        <dbType value="String" />
        <size value="255" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%thread" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@log_level" />
        <dbType value="String" />
        <size value="50" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%level" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@logger" />
        <dbType value="String" />
        <size value="255" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%logger" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@message" />
        <dbType value="String" />
        <size value="4000" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%message" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@exception" />
        <dbType value="String" />
        <size value="2000" />
        <layout type="log4net.Layout.ExceptionLayout" />
      </parameter>
    </appender>
    <root>
      <level name="INFO" />
      <appender-ref ref="SQL_Comandos" />
    </root>
    <logger name="NHibernate" additivity="false" >
      <level name="ERROR" />
      <appender-ref ref="SQL_Hibernate" />
    </logger>

They work perfectly but all logging is saving DEBUG messages, even having configured not to do so. What am I missing here开发者_如何学Go?


It should work when you configure it like this:

<logger name="NHibernate" additivity="false" >
     <level value="ERROR" />
     ...

Note: that I use value instead of name in the level node (do this for the root "level" element as well). Turning on internal debugging would reveal this kind of problem.


Just a thought, check your log appenders to see if they have something like the following configured:

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


DEBUG is a lower level than INFO, so I suspect that the DEBUG messages are being logged because the root logger is set to log at the INFO level.

See this post if you want to get the INFO messages but not the DEBUG messages.

0

精彩评论

暂无评论...
验证码 换一张
取 消