views:

548

answers:

2

I'm trying to get logging enabled on my application using Fluent NHibernate and log4net. I have tried the things described here, here, here and here. The log file is getting created, but nothing is getting written to it. The other log files for this and other applications all seam to be working OK, so I'm assuming the issue is something with my configuration.

Here is the code I have put in place to try to get this working:

The section of the config file with all of my log4net settings relevant to this APP:

<appender name="RollingFileAppenderNHibernate"
        type="log4net.Appender.RollingFileAppender">
    <file value="C:\temp\RollingLogFileNHibernate" />
    <appendToFile value="true" />
    <ImmediateFlush value="true" />
    <rollingStyle value="Date" />
    <DatePattern value="yyyyMMdd.\l\o\g" />
    <StaticLogFileName value="false" />
    <MaxSizeRollBackups value="1" />
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
    </layout>
</appender>
<logger name="NHibernate.SQL"
        additivity="false">
    <level value="ALL"/>
    <appender-ref ref="RollingFileAppenderNHibernate"/>
</logger>

My NHibernate configuration:

public static ISessionFactory CreateSessionFactory()
{
    return Fluently.Configure()
        .Database(OracleClientConfiguration.Oracle10
        .ConnectionString((conn =>
            conn.FromConnectionStringWithKey("APPDB")))
        .ShowSql())
        .Mappings(m =>
            m.FluentMappings.AddFromAssemblyOf<{ObjectName}>())
        .BuildSessionFactory();
}

In the Application_Start() of my Global.asax.cs:

log4net.Config.XmlConfigurator.Configure();

I have tried several different variations of these settings but the result is always the same, an empty log file.

A: 

If the XML is a true repesentation of your config, I can see two potential problems:

  1. There is no '>' at the end of the appender opening tag.
  2. There is &gt; at the end of the layout closing tag instead of '>'.

Of course, these may have just been caused by the copy and paste into this post.

Richard Bramley
Thanks, those were copy and paste errors. I've now corrected them.
Hamman359
A: 

It turns out that the problem had to do with the overly complicated and convoluted way that logging was handled in our framework code that we have wrapped around log4net. Once I figured out the correct hoops to jump through the logging started working correctly.

Hamman359