开发者

log4net: what am I doing wrong?

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" />
        </la开发者_如何学Goyout>
    </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>


You are doing the right thing.

Turn on this setting:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
        <add key="log4net.Internal.Debug" value="true"/>
    </appSettings>
</configuration>

And paste the resulting output here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜