简体   繁体   English

Log4net停止写入事件日志

[英]Log4net stopped writing to the event log

My application uses Log4net to write to the event viewer. 我的应用程序使用Log4net写入事件查看器。 Here's the log4net section of my program's App.config file: 这是我程序的App.config文件的log4net部分:

<log4net>
    <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
        <applicationName value="CarSystem" />
        <logName value="CarSystemLog" />
        <threshold value="DEBUG" />
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
        </layout>
    </appender>
    <root>
        <level value="DEBUG" />
        <appender-ref ref="EventLogAppender" />
    </root>
</log4net> 

Now, these settings were working fine up until about 12:30 pm the day before yesterday. 现在,这些设置工作正常,直到前天下午12:30左右。 Suddenly, (just when I need to review the messages in the log, of course) it stopped writing to the log file. 突然,(当我需要查看日志中的消息时),它停止写入日志文件。

The custom event log is in the viewer. 自定义事件日志位于查看器中。 I've rebooted the machine today, but still nothing new is going into the log. 我今天重新启动了这台机器,但仍然没有新的东西进入日志。 I increased the maximum log size to 10880 KB. 我将最大日志大小增加到10880 KB。

Why isn't log4net writing to my log file any more? 为什么不再将log4net写入我的日志文件?

Rather than looking for a solution, better find the cause. 而不是寻找解决方案,更好地找到原因。

I suggest you enable log4net's internal debug logging to file (any file) and it will dump it's troubles there. 我建议您启用log4net的内部调试日志记录到文件 (任何文件),它会在那里转储它的麻烦。 I've used this many times when my log files (should be same thing for Event Log) didn't show up. 当我的日志文件(对于事件日志应该是相同的事情)没有显示时,我已经多次使用过这个。

Instructions on how to configure it here . 关于如何配置它说明在这里

Quick steps: 快速步骤:

  • Add this to your app.config: 将其添加到您的app.config:
 <?xml version="1.0" encoding="utf-8" ?>
 <configuration>
     <appSettings>
         <add key="log4net.Internal.Debug" value="true"/>
     </appSettings>
 </configuration>
  • Add this too to the config ( configuration section). 将此添加到配置( configuration部分)。
 <system.diagnostics>
    <trace autoflush="true">
        <listeners>
              <add 
              name="textWriterTraceListener" 
              type="System.Diagnostics.TextWriterTraceListener" 
              initializeData="C:\tmp\log4net.txt" />
        </listeners>
    </trace>
 </system.diagnostics>

Any issues with permissions or whatever will then be logged to the trace file. 任何有权限或任何问题的问题都将记录到跟踪文件中。

I went back to the Log4Net documentation and noticed this statement: 我回到Log4Net文档并注意到这个声明:

it is imperative to make a logging call as early as possible during the application start-up, and certainly before any external assemblies have been loaded and invoked. 必须在应用程序启动期间尽早进行日志记录调用,当然在加载和调用任何外部程序集之前。

Well, I had the XmlConfiguration attribute in my AssemblyInfo.cs and a call to LogManager.GetLogger in the code, but it was after a call to start a monitoring object I had added to the constructor of my WPF applicaton's App object. 好吧,我在AssemblyInfo.cs中有了XmlConfiguration属性,并在代码中调用了LogManager.GetLogger ,但是在调用后我启动了一个监视对象,我已经添加到我的WPF应用程序的App对象的构造函数中。 I realized that the logging stopped after I had added this call when I read this statement and reviewed the code. 我意识到在我阅读此声明并查看代码后添加此调用后,日志记录停止了。

So I moved the call to LogManager.GetLogger to be the very first statement in the App constructor and the logging began again. 所以我将调用LogManager.GetLogger作为App构造函数中的第一个语句,并再次开始记录。 Hallelieuia! Hallelieuia!

Thanks for the help and suggestions. 感谢您的帮助和建议。

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

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