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

Using QuickLogger in a multi threaded windows service. #75

Closed AdriaanBoshoff closed 2 years ago

AdriaanBoshoff commented 2 years ago

I'm running a windows service with dynamically created custom thread objects. When in the debug build the logging works as expected by outputting to the a debug console however when the service is running as normal however only the header seems to get added to the log file and nothing else. The header essentially is the only thing that gets added into the same log file over and over.

Is there a way I should be running the logger in the a multi threaded windows service?

Logger settings in the dpr:

{$IFDEF DEBUG}
  try
    // Setup Quick Logger
    Logger.Providers.Add(GlobalLogConsoleProvider);
    with GlobalLogConsoleProvider do
    begin
      LogLevel := LOG_DEBUG;
      ShowEventColors := True;
      Enabled := True;
    end;

    // In debug mode the service acts as a console application.
    Log('TeraokaCheckWeigher DEBUG mode. Press enter to exit.', etInfo);
    TeraokaCheckWeigher := TTeraokaCheckWeigher.Create(nil);

    var
      dummy: Boolean;
    TeraokaCheckWeigher.ServiceStart(TeraokaCheckWeigher, dummy);

    ReadLn;

    // On exit, destroy the service object.
    FreeAndNil(TeraokaCheckWeigher);
  except
    on E: Exception do
    begin
      Log(E.ClassName + ': ' + E.Message, etException);
      Log('Press enter to exit.', etInfo);
      ReadLn;
    end;
  end;
{$ELSE}
  // Setup Quick Logger
  Logger.Providers.Add(GlobalLogFileProvider);
  with GlobalLogFileProvider do
  begin
    FileName := '.\Logger.log';
    DailyRotate := False;
    MaxFileSizeInMB := 20;
    LogLevel := LOG_DEBUG;
    Enabled := True;
  end;

  if not Application.DelayInitialize or Application.Installing then
    Application.Initialize;

  Application.CreateForm(TTeraokaCheckWeigher, TeraokaCheckWeigher);
  Application.Run;
{$ENDIF}

logScreenshot

exilon commented 2 years ago

Please, provide an absolute path for log file and try again.

AdriaanBoshoff commented 2 years ago

Unfortunately this did not change anything. I still get header output only. I'll make a test service for you when I have some spare time. Just to add each thread is running a telnet client with threaded events = true otherwise the OnDataAvailable event doesnt get fired in the telnet client.

AdriaanBoshoff commented 2 years ago

Seems to be a issue with using the GlobalLogFileProvider.