简体   繁体   English

Log4Net无法滚动

[英]Log4Net Not Rolling

I have a problem with Log4Net. 我对Log4Net有问题。 Running C# .Net 2.0 Log4Net Ver. 运行C#.Net 2.0 Log4Net版本。 Not Sure. 不确定。 How do I check it? 我该如何检查? Think it's 1.2 认为是1.2

It seems to only spawn a new file everytime I restart the web config. 似乎每次我重新启动Web配置时都产生一个新文件。 Any ideas why my log file isn't rolling over? 有什么想法为什么我的日志文件没有滚动?

<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
                 <maximumFileSize value="10KB" />
                 <maxSizeRollBackups value="-1" />
                 <rollingStyle value="Size" />
                 <appendToFile value="false" /> 
                 <threshold value="ON" />
                 <file value="Log.txt" />
                 <staticLogFileName value="false" />
                 <countDirection value="1" />
                 <layout type="log4net.Layout.PatternLayout">
                 <conversionPattern value="%d [%t] %-5p %c [%x] [%X{auth}] - %m%n" />
                 </layout>
</appender>

Another thing, there appears to be conflicting statements in how appendToFile is used in the documentation provided on the Apache Log4Net website. 另一件事,在Apache Log4Net网站上提供的文档中,appendToFile的使用方式似乎存在冲突。

First link http://logging.apache.org/log4net/release/config-examples.html 第一个链接http://logging.apache.org/log4net/release/config-examples.html

"The appendToFile property is set to false to prevent the appender from overwriting the existing files." “ appendToFile属性设置为false,以防止追加程序覆盖现有文件。”

Second link http://logging.apache.org/log4net/release/sdk/log4net.Appender.FileAppender.AppendToFile.html 第二个链接http://logging.apache.org/log4net/release/sdk/log4net.Appender.FileAppender.AppendToFile.html

"If the value is set to false then the file will be overwritten, if it is set to true then the file will be appended to. " “如果将该值设置为false,则该文件将被覆盖;如果将其设置为true,则该文件将被追加。”

So which is which? 那是哪一个呢? In my case, I want my log files to keep spawning new log documents without overwriting existing logs. 就我而言,我希望日志文件继续生成新的日志文档而不会覆盖现有日志。 (The maximumFileSize value is set to 10KB as a test value). (maximumFileSize值设置为10KB作为测试值)。

Change to 改成

<appendToFile value="true" /> 

The documentation in the config examples (your first link) is incorrect. 配置示例中的文档(您的第一个链接)不正确。

Also, this line is wrong: 另外,此行是错误的:

<threshold value="ON" />

The value should be a valid logging level, eg "Debug" or "All" 该值应为有效的日志记录级别,例如“ Debug”或“ All”

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

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