我正在使用NHibernate&在我的项目中使用C#和MySql db的Net Persistence API,我有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,
答案 0 :(得分:5)
logger
节点不正确。试试这种方式:
<root>
<level value="INFO"/>
<appender-ref ref="RollingLogFileAppender"/>
</root>
<logger name="NHibernate" additivity="false">
<level value="WARN"/>
<appender-ref ref="RollingFileAppender"/>
</logger>