I have a logback file that logs events using RollingFileAppender. However, if I run the main class numerous times, the log file does not always produce, sometimes it creates with logs, and sometimes it only creates an empty file. There are certain cases where the file itself is not created.
LogBack file:
<configuration debug="true">
<property name="DEFAULT_LOG_LEVEL" value="DEBUG"/>
<property name="DATE_PATTERN" value="%d{yyyy.MM.dd.HH.mm.ss}" />
<appender name="ABCD" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>C://abc.log</file>
<append>false</append>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>C://abc_{DATE_PATTERN}.log</fileNamePattern>
<TimeBasedFileNamingAndTriggeringPolicy class="com.example.timer.policy.TimePolicy"/>
</rollingPolicy>
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator>
<expression>return logger.contains("com.example.logger.logevents");</expression>
</evaluator>
<OnMismatch>DENY</OnMismatch>
<OnMatch>ACCEPT</OnMatch>
</filter>
</appender>
<root level="${DEFAULT_LOG_LEVEL}">
<appender-ref ref="ABCD"/>
</root>
<logger level="INFO" name="ABCD" additivity="false">
<appender-ref ref="ABCD">
</logger>
</configuration>
Main Class:
private static Logger abcLogger=LoggerFactory.getLogger("com.example.logger.logevents");
public static void main(String[] args){
abcLogger.info("Hi, Logging event from here");
}
I tried changing the appender to FileAppender but still faced the same issues.