2

我在我的项目中使用 NHibernate & Net Persistence API 和 C# 和 MySql db,我有 UI 层 (ASP.NET)、业务层和数据访问层 (DAL)。对于日志记录,我使用的是 log4net。

我的 UI 层中有 web.config 文件,我在其中放置了以下代码行来禁用 NHibernate INFO 级别日志记录:

<log4net debug="true">
        <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
            <file value="Log.txt"/>
            <appendToFile value="true"/>
            <rollingStyle value="Date"/>
            <datePattern value="dd-MM-yyyy"/>
            <maxSizeRollBackups value="20"/>
            <maximumFileSize value="50MB"/>
            <staticLogFileName value="true"/>
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n"/>
            </layout>
        </appender>
        <root>
            <logger name="NHibernate" additivity="false">
                <level value="WARN"/>
                <appender-ref ref="RollingFileAppender"/>
            </logger>
            <level value="INFO"/>
            <appender-ref ref="RollingLogFileAppender"/>            
        </root>
    </log4net>

但它不工作!我仍然可以看到 INFO 级别的日志,日志中的一些行是:

INFO  2013-01-09 01:15:06,383  6993ms Environment            lambda_method      - NHibernate 3.2.0.4000 (3.2.0.4000)
INFO  2013-01-09 01:15:06,386  6996ms Environment            lambda_method      - hibernate-configuration section not found in application configuration file
INFO  2013-01-09 01:15:06,387  6997ms Environment            lambda_method      - Bytecode provider name : lcg
INFO  2013-01-09 01:15:06,388  6998ms Environment            lambda_method      - Using reflection optimizer
INFO  2013-01-09 01:15:07,171  7781ms Dialect                lambda_method      - Using dialect: NHibernate.Dialect.MySQLDialect
INFO  2013-01-09 01:15:07,390  8000ms Dialect                lambda_method      - Using dialect: NHibernate.Dialect.MySQLDialect
INFO  2013-01-09 01:15:07,407  8017ms Mappings               lambda_method      - duplicate import: JDAL.Impl.Entities.EntityName, JDAL, Version=1.0.0.0,
4

1 回答 1

7

logger节点不正确。试试这种方式:

<root>
   <level value="INFO"/>
   <appender-ref ref="RollingLogFileAppender"/>            
</root>
<logger name="NHibernate" additivity="false">
    <level value="WARN"/>
    <appender-ref ref="RollingFileAppender"/>
</logger>
于 2013-01-09T08:39:33.930 回答