开发者

log4net log file is empty in production, not in development

开发者 https://www.devze.com 2023-04-04 09:07 出处:网络
For a Windows service written in C# 4, I have log4net configured and working fine in development. But not in p开发者_C百科roduction.

For a Windows service written in C# 4, I have log4net configured and working fine in development. But not in p开发者_C百科roduction.

Here is my config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    </configSections>

    <log4net>
        <appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
            <file value="Logs/Log.xml"/>
            <appendToFile value="true"/>
            <rollingStyle value="Size"/>
            <maxSizeRollBackups value="10"/>
            <maximumFileSize value="100MB"/>
            <layout type="log4net.Layout.XmlLayout">
                <param name="Prefix" value=""/>
            </layout>
        </appender>

        <root>
            <level value="ALL"/>
            <appender-ref ref="FileAppender"/>
        </root>
    </log4net>
</configuration>

Within my AssemblyInfo.cs I have:

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

When I run the app locally, stuff is written to the log as expected. When I run it on the server, the log file is created at the correct path but it remains empty. Not a single character is written to the log.

Clearly my configuration is being picked up since the file is at the proper location with the proper extension.


As a workaround, I removed the [assembly: log4net.Config.XmlConfigurator(Watch = true)] line from the assembly and just did it in code on application start.


I just had the same issue and fixed that, [assembly: log4net.Config.XmlConfigurator(Watch = true)] was in ninjectwebcommon file instead of assembly info. After i moved that to assemblyinfo it start working


This is a silly question... but are you sure your service has started correctly and is doing stuff?

I'd add the console appender and maybe the eventlong appender too, and try running your service as a console app, if possible, to have a look?

I'd say, since the log file is being created, things look fine with log4net...?

0

精彩评论

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

关注公众号