log4net没有给出任何响应或记录

时间:2016-06-28 14:33:36

标签: c# logging log4net

我正在尝试使用log4net将错误写入文件。我没有错误,没有日志文件。我在这里缺少什么?

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

<log4net>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
  <param name="File" value="c:\Temp\testlog4net.txt" />
  <param name="AppendToFile" value="true" />
  <layout type="log4net.Layout.PatternLayout">
    <param name="Header" value="[Header]\r\n" />
    <param name="Footer" value="[Footer]\r\n" />
    <param name="ConversionPattern" value="%d [%t] %-5p %c %m%n" />
  </layout>
</appender>
<root>
  <level value="INFO" />
  <appender-ref ref="LogFileAppender" />
</root>
</log4net>
<appSettings>
  <add key="log4net.Internal.Debug" value="true"/>
</appSettings>

代码:

private static ILog _fileLogger = LogManager.GetLogger(typeof(LogHelper));

public static void Error(Exception e)
    {
        _fileLogger.Error(e);
    }

1 个答案:

答案 0 :(得分:2)

您应该将此添加到

  

的AssemblyInfo.cs

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]