1

As per the documentation, DailyRollingFileAppender will do the file rolling at midnight of each day. But, if we close the appender and open the new appender for same log file, then it roll over the existing file and creates the new one. My requirement is, to reuse of the existing log file instead of rolling the log file. Please someone help me to achieve this.

Thank you for your advanced help

1 Answers1

0

This is basically a historical behaviour. Recently a contributor has added a RollOnClose property the appender on 1.2.x branch that allows you to turn this behaviour off.

wilx
  • 17,697
  • 6
  • 59
  • 114
  • I have upgraded log4cplus version to 1.2.0 version and set the rollonclose to false. Now, rolling doesn't happen while closing log file as expected. But ,rolling take place if I open the same file again through the DailyRollingFileAppender class. My requirement is, to reuse the existing log file without rolling them if we initialize it again through appender – Stanley Emmanuel Feb 05 '16 at 13:00
  • @StanleyEmmanuel: Try the [`TimeBasedRollingFileAppender`](https://github.com/log4cplus/log4cplus/blob/1.2.x/include/log4cplus/fileappender.h#L379). – wilx Feb 05 '16 at 13:05
  • Thanks for your update. I replaced the TimeBasedRollingFileAppender instead of DailyRollingFileAppender. Now this time rolling doen't happened while reopening the log file(which is my desired result), but the existing data in the log file gets truncated. My requirement is, to retain the existing data in log file while reopening. Thanks for your advanced help. – Stanley Emmanuel Feb 11 '16 at 11:46