简体   繁体   中英

log4net log file is not getting created in C#

log file is not getting created, using below call to get logger and config file. is it required to give full path for file?

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

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821" requirePermission="false"/>
    </configSections>

    <!-- Log4net Logging Setup -->
    <log4net>
        <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
            <file value="log.txt" />
            <appendToFile value="true" />
            <rollingStyle value="Size" />
            <maxSizeRollBackups value="50" />
            <maximumFileSize value="50MB" />
            <staticLogFileName value="true" />
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
            </layout>
        </appender>
        <root>
            <level value="ALL" />
            <appender-ref ref="RollingFileAppender" />
        </root>
    </log4net>
</configuration>

Does your code call

log4net.Config.XmlConfigurator.Configure();

on startup?

The <root> section I use has priority , not level :

    <root>
        <priority value="ALL" />
        <appender-ref ref="LogFileAppender" />
    </root>

(Apparently, that's not the issue https://stackoverflow.com/a/24188507/21336 )

after adding below line in AssemblyInfo.cs, could see log file getting created and logs coming. [assembly: log4net.Config.XmlConfigurator(Watch = true)]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM