开发者

How to force log4net to always use the same file

开发者 https://www.devze.com 2023-03-15 16:36 出处:网络
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

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>


Check out the difference between FileAppender and RollingFileAppender here. It sounds like you want FileAppender with appendToFile set to true.

<appender name="FileAppender" type="log4net.Appender.FileAppender">
    <file value="c:\logs\mylog.txt" />
    <appendToFile value="true" />
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date - %message%newline" />
    </layout>
</appender>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号