我已经从配置文件以编程方式创建 log4net 日志:
var properties = new NameValueCollection
{
{"configType", "FILE"},
{"configFile", @"c:/log4net.config"}
};
Common.Logging.LogManager.Adapter = new Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter(properties);
这是我的log4net.config
(为简单起见,按照鸽子的建议进行了编辑):
<log4net>
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="c:/log.log" />
<appendToFile value="true" />
<maximumFileSize value="100KB" />
<maxSizeRollBackups value="5" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender>
<root>
<level value="All" />
<appender-ref ref="RollingFile" />
</root>
<logger name="NHibernate">
<level value="All" />
<appender-ref ref="RollingFile" />
</logger>
</log4net>
我让 Spring.NET 成功登录到该文件,但不是 NHibernate。Nhibernate 配置流畅:
protected override void PostProcessConfiguration(Configuration config)
{
base.PostProcessConfiguration(config);
var msSqlCfg = MsSqlConfiguration.MsSql2000.ConnectionString(ConnectionString)
.ShowSql();
Fluently.Configure(config).Database(msSqlCfg)
.Mappings(m => m.FluentMappings.Add<EmployeeMap>())
// Other mappings
.BuildSessionFactory();
}
我应该修复什么才能让 Nhibernate 日志正常工作?