Log4net随机停止记录. [英] Log4net randomly stops logging.

查看:65
本文介绍了Log4net随机停止记录.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用log4net来构建ASP.Net-MVC应用程序进行日志记录,但是记录器似乎只是随机停止.它会愉快地记录一段时间,然后停止,然后在一段时间后再次启动.我什至不知道是什么使它恢复日志记录.我并不是说丢失了一些消息-有时它会消失很长时间,例如一个小时左右.

I am currently building an ASP.Net-MVC Application using log4net for logging, but the logger seems to just stop at random. It will happily log for awhile, and then stop, and then will start again after a period of time. I am not even sure what it is that makes it resume logging. I'm not talking about just a few messages being lost- sometimes it dissappears for a long period of time, such as an hour or so.

为什么会这样停止并开始?我应该如何正确配置它,以使其不会像它那样随机停止?

Why would it stop and start like this? How should I properly configure this so that it will not randomly stop as it does?

这是我的配置:

<log4net debug="true">
<appender name="RollingLogFileAppender"
        type="log4net.Appender.RollingFileAppender">

  <file value="..\Logs\\CurrentLog.txt" />
  <appendToFile value="true" />
  <datePattern value="yyyyMMdd" />

  <rollingStyle value="Date" />
  <filter type="log4net.Filter.LevelRangeFilter">
    <acceptOnMatch value="true" />

    <levelMin value="INFO" />
    <levelMax value="FATAL" />
  </filter>

  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern
    value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
  </layout>

</appender>

<root>
  <level value="INFO" />
  <appender-ref ref="RollingLogFileAppender" />
</root>

推荐答案

Log4Net将如果出现问题并且无法写入其附加程序,则会无声地失败.这实际上是一件好事,因为这意味着一些失败的日志记录不会导致正常运行的系统崩溃,但是当某些内容未按预期进行日志记录时,这可能会很烦人.

Log4Net will fail silently if something goes wrong and it is unable to write to its appenders. This is actually a good thing, since it means a bit of failed logging won't bring down an otherwise healthy system, but it can be annoying when something isn't logging as you expect.

您最好的选择是打开log4net自己的内部日志记录进行一些诊断,并(希望)弄清楚其失败的原因.

Your best bet is to turn on log4net's own internal logging to do some diagnostics and (hopefully) work out why it's failing.

因此,在您应用的配置文件中添加:

So in your app's config file add:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
        <add key="log4net.Internal.Debug" value="true"/>
    </appSettings>
</configuration>

这将打开内部日志记录,并将其发送到System.Diagnostics.Trace,因此您可以添加:

which will turn on the internal logging, which gets sent to System.Diagnostics.Trace, so you can add:

<configuration>
    ...
    <system.diagnostics>
        <trace autoflush="true">
            <listeners>
                <add 
                    name="textWriterTraceListener" 
                    type="System.Diagnostics.TextWriterTraceListener" 
                    initializeData="C:\tmp\log4net.txt" />
            </listeners>
        </trace>
    </system.diagnostics>
    ...
</configuration>

将其捕获到文件中.

这篇关于Log4net随机停止记录.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆