如何强制 log4net 始终使用相同的文件
我有一个每月运行 2 次的进程,我想记录它在做什么,然后最后通过电子邮件发送日志文件。我昨晚运行它时注意到,当午夜过去时,它不断将所有内容记录到 mylog.txt
中,但将前几天的日志放入 mylog.txt.6-23-2011< /代码>。我如何告诉它不要这样做并始终使用相同的文件?这是我的配置:
<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.SimpleLayout" />
</appender>
<appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
<file value="c:\logs\mylog.txt" />
<appendToFile value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date - %message%newline" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="ConsoleAppender" />
<appender-ref ref="FileAppender" />
</root>
</log4net>
I have a process that runs 2x a month and I want to log what's it doing and then send the log file in an email at the end. What I noticed when I ran it last night was that when it passed midnight it kept logging everything to mylog.txt
but put the previous days logs in mylog.txt.6-23-2011
. How do I tell it to not do that and always use the same file? Here's my configuration:
<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.SimpleLayout" />
</appender>
<appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
<file value="c:\logs\mylog.txt" />
<appendToFile value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date - %message%newline" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="ConsoleAppender" />
<appender-ref ref="FileAppender" />
</root>
</log4net>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此处查看 FileAppender 和 RollingFileAppender 之间的区别。听起来您希望 FileAppender 的appendToFile 设置为true。
Check out the difference between FileAppender and RollingFileAppender here. It sounds like you want FileAppender with appendToFile set to true.