exilon / QuickLogger

Powerful and flexible library for logging on files, console, memory, email, rest, eventlog, syslog, slack, telegram, redis, logstash, elasticsearch, influxdb, graylog, Sentry, Twilio, ide debug messages and throw events for Delphi/Firemonkey/freepascal/.NET (Windows/Linux/OSX/IOS/Android).
Apache License 2.0
381 stars 84 forks source link

LogFileProvider not working anymore #95

Closed pjrobin closed 1 year ago

pjrobin commented 1 year ago

I think something is brocken in the Pull request #91: Before the pull:
in my log folder, i had myapp.log, myapp.1.log and so on

Now: I have myapp.log, myapp.01.log When I start the application and myapp.01.log already exists then the logfileprovider will produce an exception when trying to enable it in RotateLog: 'Can''t rotate log file: the file already exists '#$D#$A'[C:\Users\Public\Documents\Logs\myapp.01.log]'

pjrobin commented 1 year ago

Seems to be a problem in GetLogFileBackup: is is searching for 'C:\Users\Public\Documents\Logs\myapp.01.*.log.zip'

pjrobin commented 1 year ago

This could be the fix:

function TLogFileProvider.GetLogFileBackup(cNumBackup: Integer; zipped: Boolean): string;
var
  SearchRec: TSearchRec;
  i: Integer;
begin
  // Doing this twice to be backward compatible independent if the numbackup is formatted or not
  for i := 0 to 1 do
  begin
    if DailyRotate then
      Result := CalcRotateLogFileName (cNumBackup, '*', zipped, i = 0)
    else
      Result := CalcRotateLogFileName (cNumBackup, '', zipped, i = 0);

    if findfirst (Result, faAnyFile, SearchRec) = 0 then
      Result := TPath.GetDirectoryName (Result) + PathDelim + SearchRec.Name
    else
      Result := '';
    FindClose (SearchRec);
    if Result <> '' then
      Exit;
  end;
end;