#1 2025-04-01 10:23:29

anouri
Member
Registered: 2024-02-11
Posts: 87

TSynLog Instance problem

I can't figure out this code work properly. when I replace myLog1 with TSynLog it works.

var
  myLog1,myLog2: TSynLog;
begin
  myLog1 := TSynLog.Create();

  myLog1.Family.Level := LOG_VERBOSE;
  myLog1.Family.DestinationPath := 'D:\SynLog1\';
  myLog1.Family.FileExistsAction := acAppend;

  myLog1.Log(sllInfo, 'Logging initialized.');
end;

Last edited by anouri (2025-04-01 10:23:47)

Offline

#2 2025-04-01 16:45:15

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,965
Website

Re: TSynLog Instance problem

Please follow the documentation.
Never ever use TSynLog.Create.
Use the class type itself, the TSynLog.Add or Enter to retrieve a local instance if you need.

Offline

#3 2025-04-06 13:45:24

anouri
Member
Registered: 2024-02-11
Posts: 87

Re: TSynLog Instance problem

Yes. Solved. thanks alot
for creating multiple file I am using multiple classes:

  TDbLog = class(TSynLog);   // Log for database operations
  TApiLog = class(TSynLog);  // Log for API calls

Is this correct ?

Last edited by anouri (2025-04-06 14:02:24)

Offline

#4 2025-04-06 15:35:05

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,965
Website

Re: TSynLog Instance problem

Exactly right.

smile

Offline

Board footer

Powered by FluxBB