转载

RollingFileAppender中的FileNamePattern – logback配置

我的logback配置文件中有以下RollingFileappender.

<appender name="RollingFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
  <File>C:/Files/MyLogFile.log</File>      
  <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 
  <FileNamePattern>C:/Files/MyLogFile.%d{yyyy-MM-dd}.log</FileNamePattern>       
  <MaxHistory>30</MaxHistory>     
  </rollingPolicy>      
  <encoder>
      <pattern>%date %level [%thread] %logger{60} [%file:%line] %msg%n</pattern>
    </encoder> 
  </appender>

它将文件写入上述目录作为MyLogFile.log,但不附加FileNamePattern中指定的日期.任何想法如何设法将日期追加到我的fileName.谢谢.

TimeBasedRollingPolicy

的文档说明:

Note that the file property in RollingFileAppender (the parent of

TimeBasedRollingPolicy ) can be either set or omitted. By setting the

file property of the containing FileAppender , you can decouple the

location of the active log file and the location of the archived log

files. The current logs will be always targeted at the file specified

by the file property. It follows that the name of the currently active

log file will not change over time. However, if you choose to omit the

file property, then the active file will be computed anew for each

period based on the value of fileNamePattern .

在你的情况下,只需省略文件属性.

http://stackoverflow.com/questions/10953915/filenamepattern-in-rollingfileappender-logback-configuration

原文  https://codeday.me/bug/20181015/287937.html
正文到此结束
Loading...