EFileNotFoundException when log rotation is set to zero
luebbe opened this issue · 0 comments
luebbe commented
#54 triggered my memory. During testing loggerpro, I came across the following problem: If you set the log rotation to zero, like
in LoggerPro.Config in the file appender example
_Log := BuildLogWriter([
TLoggerProFileAppender.Create(0, 5, '..\..', [],
TLoggerProFileAppender.DEFAULT_FILENAME_FORMAT, DEFAULT_LOG_FORMAT)
...
an EFileNotFoundException
is raised in procedure TLoggerProFileAppenderBase.RetryMove
.
The simplest solution for me would be to either assert that the value is at least one or set it to Min(1, ...) in the constructor. I consider no rotation an invalid use case :)
So either:
constructor TLoggerProFileAppenderBase.Create(...
begin
Assert(aMaxBackupFileCount > 0, 'Log rotation must be at least one.');
...
or
constructor TLoggerProFileAppenderBase.Create(...
begin
...
fMaxBackupFileCount:= Min(1, aMaxBackupFileCount)
...