简体   繁体   English

在C#中没有创建log4net日志文件

[英]log4net log file is not getting created in C#

log file is not getting created, using below call to get logger and config file. 没有创建日志文件,使用下面的调用来获取logger和配置文件。 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 ,而不是level

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

(Apparently, that's not the issue https://stackoverflow.com/a/24188507/21336 ) (显然,这不是问题https://stackoverflow.com/a/24188507/21336

after adding below line in AssemblyInfo.cs, could see log file getting created and logs coming. 在AssemblyInfo.cs中添加以下行后,可以看到日志文件已创建并且日志即将到来。 [assembly: log4net.Config.XmlConfigurator(Watch = true)] [assembly:log4net.Config.XmlConfigurator(Watch = true)]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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