简体   繁体   中英

Log4net Custom File Pattern and Folder Location in c#

I start to use the log4net for my log file, then I want to save the file log base in the date, and I made a couple of research then my configuration looks like this, it's working properly but one problem remaining if not creating new file when the date change, did I miss something in my configuration?

Here is my configuration.

<appender name="AppLogFileAppender" type="log4net.Appender.RollingFileAppender">
  <file type="log4net.Util.PatternString" value="C:/ProgramData/AppTitle/Logs/Application/%date{yyyy-MM}/%date{dd}-log.txt"/>
  <appendToFile value="true"/>
  <rollingStyle value="Date"/>
  <maximumFileSize value="5MB"/>
  <maxSizeRollBackups value="20"/>
  <datePattern value="yyyy-MM-dd"/>
  <layout type="log4net.Layout.PatternLayout">
    <param name="ConversionPattern" value="[%d %-5p] : %m%n%n" />
  </layout>
</appender>

You can refer to the following link: Log4net rolling daily filename with date in the file name

There are numerous items which I can see is quite different. For Example you can try adding the below items and see if it works for you. Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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