tags:

views:

98

answers:

1

Being a log4net newb / boob I just copied lines from an NHibernate example project where I can see the log.txt file is updated. Is there a quick answer why mine isn't creating the file?

Cheers,
Berryl

[assembly: log4net.Config.XmlConfigurator(Watch = true)]

I saw another post here saying this should go in AssemblyInfo, but in the example project this is just another line in a static helper class. Not wanting to 'mess with' assemblyInfo I also put this in a static helper, along with the following to actually log in the same static helper class:

private static readonly log4net.ILog _log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType );

And in app.config, I have

<configSections>
    <section
        name="log4net"
        type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"
    />
</configSections>

    <!-- This section contains the log4net configuration settings -->
<log4net>
    <!-- Define an output appender (where the logs can go) -->
    <appender name="LogFileAppender" type="log4net.Appender.FileAppender, log4net">
        <param name="File" value="log.txt" />
        <param name="AppendToFile" value="false" />
        <layout type="log4net.Layout.PatternLayout, log4net">
            <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />
        </layout>
    </appender>
    <appender name="LogDebugAppender" type="log4net.Appender.DebugAppender, log4net">
        <layout type="log4net.Layout.PatternLayout, log4net">
            <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n"/>
        </layout>
    </appender>

    <!-- Setup the root category, set the default priority level and add the appender(s) (where the logs will go) -->
    <root>
        <priority value="ALL" />
        <appender-ref ref="LogFileAppender" />
        <appender-ref ref="LogDebugAppender"/>
    </root>

    <!-- Specify the level for some specific namespaces -->
    <!-- Level can be : ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF -->
    <logger name="NHibernate">
        <level value="ALL" />
    </logger>
</log4net>
A: 

I'm not sure what the problem is but could you try this this configuration mecanism instead

GLOBAL.ASAX

protected void Application_Start(Object sender, EventArgs e)
{
    log4net.Config.XmlConfigurator.Configure();
}

Are you sure you're looking in the correct place for the log file?

Not very sure about this but you could also try to add an appender to the nhibernate logger

<logger name="NHibernate">
        <level value="ALL" />
        <appender-ref ref="LogFileAppender" />
</logger>
Claudio Redi
I just did a Windows search at the solution root folder, although it I think it should wind up in debug for the calling assembly (Tests in this case). It is a desktop app though...
Berryl
The log file should be on the folder where the exe is placed (probably something like Debug/bin)
Claudio Redi
It isn't showing up there. Can the call to the XmlConfigurator be in any class in the executing assembly? I have it in a unit test now but it still isn't being generated
Berryl
You can call it anywhere. I'd also suggest you to create a path "c:\temp" and store the log there.
Claudio Redi