danieleteti / loggerpro

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

EInOutError in TLoggerProFileAppender #54

Closed chomps1 closed 2 years ago

chomps1 commented 2 years ago

Dear Daniele. An EInOutError occurs in procedure RotateLog if you want to write messages with different tags in one file. The following test produces the error:

procedure TForm1.Button1Click(Sender: TObject);
var
  Lg: ILogWriter;
  i: Integer;
begin
  Lg := BuildLogWriter([TLoggerProFileAppender.Create(10, 5,
    TPath.Combine(ExtractFileDir(ParamStr(0)), 'LogDir'), [], '%s.%2.2d.log')]); // initialized to write different tags in one file
  Lg.Info('Test started V1.0!', 'Test'); // first tag 'Test'

  for i := 0 to 100 do
    Lg.Info('Test LoopCnt: %d!',[i],'Loop'); // second tag 'Loop'

  Sleep(2000);

end;
chomps1 commented 2 years ago

With the latest TLoggerProSimpleFileAppender the solution is quite simple and I can use the filter function to filter different tags. I would close the issue as "won't fix" due to the simple solution. Thank you.

procedure TForm1.Button1Click(Sender: TObject);
  var
  Lg: ILogWriter;
  i: Integer;
begin
  Lg := BuildLogWriter([
    TLoggerProFilter.Build(
      TLoggerProSimpleFileAppender.Create(10, 5,
        TPath.Combine(ExtractFileDir(ParamStr(0)), 'LogDir'), [], '%s.%2.2d.log'),
      function(ALogItem: TLogItem): boolean
      begin
        Result := true;
      end)
  ]);

  Lg.Info('Test started V1.0!', 'Test'); // first tag 'Test'

  for i := 0 to 100 do
    Lg.Info('Test LoopCnt: %d!',[i],'Loop'); // second tag 'Loop'

  Sleep(2000);
end;