1

我的根记录器捕获所有级别的日志,除了off. 我的等级设置为INFO。我搜索了某个地方是否更改了级别,但我一无所获。

当我将记录器IBatisNet.DataMapper.Commands.DefaultPreparedCommand放到 时DEBUG,日志是由SpecificAppender. 但是,即使 root 设置为 ,日志也会出现在控制台中INFO

这是我的代码:

<?xml version="1.0" encoding="utf-8" ?>
<!-- This section contains the log4net configuration settings -->
<configuration>
<configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,     log4net" />
</configSections>
<log4net>
    <!-- Define some output appenders -->
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
        <param name="File" value="d:/logs/vol/vol.log" />
        <param name="AppendToFile" value="true" />
        <param name="MaxSizeRollBackups" value="3" />
        <param name="MaximumFileSize" value="500KB" />
        <param name="RollingStyle" value="Size" />
        <param name="StaticLogFileName" value="true" />

        <layout type="log4net.Layout.PatternLayout">
            <param name="ConversionPattern" value="%d{HH:mm:ss,fff} [%t] %-5p %c{1} - %m%n" />
        </layout>
    </appender>

    <appender name="IBatisAppender" type="log4net.Appender.RollingFileAppender">
        <param name="File" value="d:/logs/vol/IBatis.log" />
        <param name="AppendToFile" value="true" />
        <param name="MaxSizeRollBackups" value="3" />
        <param name="MaximumFileSize" value="1000KB" />
        <param name="RollingStyle" value="Size" />
        <param name="StaticLogFileName" value="true" />

        <layout type="log4net.Layout.PatternLayout">
            <param name="ConversionPattern" value="%d{HH:mm:ss,fff} [%t] %-5p %c{1} - %m%n" />
        </layout>
    </appender>

    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
        <layout type="log4net.Layout.PatternLayout">
            <param name="ConversionPattern" value="%d{HH:mm:ss,fff} [%t] %-5p %c{1} - %m%n" />
        </layout>
    </appender>

    <appender name="IBatisBufferingAppender" type="log4net.Appender.BufferingForwardingAppender" >
        <bufferSize value="60"/>
        <appender-ref ref="IBatisAppender" />
    </appender>

    <appender name="LogBufferingAppender" type="log4net.Appender.BufferingForwardingAppender" >
        <bufferSize value="60"/>
        <appender-ref ref="RollingLogFileAppender" />
    </appender>

    <appender name="SpecificAppender" type="log4net.Appender.RollingFileAppender">
        <file value="d:/logs/vol/" />
        <appendToFile value="true"/>
        <datePattern value="Volu\me\trieSpeci\fic_yyyy-MM-dd.lo\g"/>
        <rollingStyle value="Date"/>
        <maxSizeRollBackups value="30"/>
        <appendToFile value="true"/>
        <staticLogFileName value="false"/>
        <layout type="log4net.Layout.PatternLayout">
            <param name="ConversionPattern" value="%d{HH:mm:SS,fff} [%t] %-5p %c{1} - %m%n" />
        </layout>
        <filter type="log4net.Filter.StringMatchFilter">
            <stringToMatch value="No -->"/>
            <acceptOnMatch value ="true" />
        </filter>
        <filter type="log4net.Filter.StringMatchFilter">
            <stringToMatch value="Statement Id: [vol.Delete"/>
            <acceptOnMatch value ="false" />
        </filter>
        <filter type="log4net.Filter.StringMatchFilter">
            <stringToMatch value="] Types: ["/>
            <acceptOnMatch value ="false" />
        </filter>
        <filter type="log4net.Filter.StringMatchFilter">
            <stringToMatch value="Statement Id: [vol."/>
            <acceptOnMatch value ="true" />
        </filter>
        <filter type="log4net.Filter.DenyAllFilter"/>
    </appender>

    <root>
        <level value="INFO" />
        <appender-ref ref="ConsoleAppender" />
        <appender-ref ref="LogBufferingAppender" />
    </root>

    <logger name="PROGvolBatch.Services.CIService">
        <level value="INFO" />
        <appender-ref ref="SpecificAppender"/>
    </logger>

    <logger name="IBatisNet.DataMapper.Commands.DefaultPreparedCommand">
        <level value="DEBUG" />
        <appender-ref ref="SpecificAppender"/>
    </logger>

    <logger name="IBatisNet.DataMapper.Configuration.Cache.CacheModel">
        <level value="OFF" />
        <appender-ref ref="IBatisBufferingAppender" />
    </logger>
    <logger name="IBatisNet.DataMapper.LazyLoadList">
        <level value="OFF" />
        <appender-ref ref="IBatisBufferingAppender" />
    </logger>
    <logger name="IBatisNet.DataMapper.SqlMapSession">
        <level value="OFF" />
        <appender-ref ref="IBatisBufferingAppender" />
    </logger>
    <logger name="IBatisNet.Common.Transaction.TransactionScope">
        <level value="OFF" />
        <appender-ref ref="IBatisBufferingAppender" />
    </logger>
    <logger name="IBatisNet.DataAccess.DaoSession">
        <level value="OFF" />
        <appender-ref ref="IBatisBufferingAppender" />
    </logger>
    <logger name="IBatisNet.DataAccess.Configuration.DaoProxy">
        <level value="OFF" />
        <appender-ref ref="IBatisBufferingAppender" />
    </logger>
    <logger name="IBatisNet.DataMapper.Configuration.Statements.PreparedStatementFactory">
        <level value="OFF" />
        <appender-ref ref="IBatisBufferingAppender" />
    </logger>
    <logger name="IBatisNet.DataMapper.Commands.IPreparedCommand">
        <level value="OFF" />
        <appender-ref ref="IBatisBufferingAppender" />
    </logger>
</log4net>

我尝试将根的级别更改为其他内容,但我总是得到相同的结果。

4

1 回答 1

0

这似乎是 log4net 的工作方式。当您的配置文件被处理时,它的行为就好像它已被配置为:

<logger name="IBatisNet.DataMapper.Commands.DefaultPreparedCommand" additivity="false">
    <level value="DEBUG" />
    <appender-ref ref="SpecificAppender"/>
    <appender-ref ref="ConsoleAppender" />
    <appender-ref ref="LogBufferingAppender" />
</logger>

幸运的是,有一个解决方法,那就是在您的 appender 上设置一个级别过滤器,例如为 ConsoleAppender:

 <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
  <layout type="log4net.Layout.PatternLayout">
    <param name="ConversionPattern" value="%d{HH:mm:ss,fff} [%t] %-5p %c{1} - %m%n" />
  </layout>
  <filter type="log4net.Filter.LevelRangeFilter">
    <levelMin value="INFO" />
    <acceptOnMatch value="true" />
  </filter>    
</appender>

最好将 appender 重命名为更具描述性的名称,例如InfoConsoleAppender. 此外,如果您希望能够在调试级别将一些记录器记录到控制台,那么您可能需要另一个 un-filtered ConsoleAppender

于 2013-08-31T10:15:24.353 回答