Configure Nhibernate log into file

647 Views Asked by At

I have programmatically create log4net log from config file:

var properties = new NameValueCollection
            {
                {"configType", "FILE"},
                {"configFile", @"c:/log4net.config"}
            };
Common.Logging.LogManager.Adapter = new Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter(properties);

This is my log4net.config (EDITED for simplicity as dove suggested) :

<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>

I got Spring.NET successfuly logging into that file, but not NHibernate. Nhibernate is configured fluenltly:

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();
    }

What should I fix to get Nhibernate log working?

1

There are 1 best solutions below

3
On

Does it log if you generate statistics?

Configuration.ExposeConfiguration(c => 
            c.SetProperty("generate_statistics", "true"));

To narrow things down can you remove additivity flag and appeder from within logger and just log one to start, i.e. exactly like this

<logger name="NHibernate">
  <level value="ALL" />
</logger>