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 thefile
property inRollingFileAppender
(the parent of
TimeBasedRollingPolicy
) can be either set or omitted. By setting the
file property of the containingFileAppender
, 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 thefile
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 offileNamePattern
.
在你的情況下,只需省略檔案屬性.
http://stackoverflow.com/questions/10953915/filenamepattern-in-rollingfileappender-logback-configuration