<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt">Hello everyone,<br>I am trying to specify the size of my log file in my Java code. However, no file is written in the specified directory. Using a FileAppender without a triggering policy works fine. But I would like to specify the max. log file size. Any help is appreciated :) Thanx in advance!<br><div><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;">Here is my code:</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><br> LoggerContext loggerContext = (LoggerContext)
LoggerFactory.getILoggerFactory();<br> RollingFileAppender<ILoggingEvent> fileAppender = new RollingFileAppender<ILoggingEvent>();<br> fileAppender.setContext(loggerContext);<br> fileAppender.setFile("C:\\log\\log.txt");<br> <br> SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>();<br> triggeringPolicy.setMaxFileSize("5MB");<br> triggeringPolicy.start();<br><br> PatternLayoutEncoder encoder = new PatternLayoutEncoder();<br> encoder.setContext(loggerContext);<br> encoder.setPattern("%d %level %logger:
%msg%n");<br> encoder.start();<br><br> fileAppender.setEncoder(encoder);<br> fileAppender.setTriggeringPolicy(triggeringPolicy);<br> fileAppender.start();<br><br> Logger logbackLogger = loggerContext.getLogger("ExportMapToFile");<br> ((ch.qos.logback.classic.Logger) logbackLogger).addAppender(fileAppender);<br> <br> logbackLogger.info(info);<br> fileAppender.stop();<br> triggeringPolicy.stop();<br> encoder.stop();<br> <br></div></div></body></html>