I have the following RollingFileappender in my logback configuration file.
<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>
It does write a file to the above directory as MyLogFile.log but does not append the date as specified in the FileNamePattern
. Any ideas how can I manage to append the date in my fileName. Thanks.
The documentation for TimeBasedRollingPolicy
states:
Note that the
file
property inRollingFileAppender
(the parent ofTimeBasedRollingPolicy
) 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 thefile
property, then the active file will be computed anew for each period based on the value offileNamePattern
.
In your case, just omit the file
property.