danieleteti / loggerpro

An modern and pluggable logging framework for Delphi
Apache License 2.0
357 stars 91 forks source link

EFileNotFoundException when log rotation is set to zero #60

Closed luebbe closed 2 years ago

luebbe commented 2 years ago

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)
  ...