2023-02-27 12:26:25 +01:00
|
|
|
program SimpleConsole_appender;
|
|
|
|
|
|
|
|
{$APPTYPE CONSOLE}
|
|
|
|
|
|
|
|
{$R *.res}
|
|
|
|
|
|
|
|
uses
|
|
|
|
System.SysUtils, System.Classes, System.Threading,
|
|
|
|
LoggerPro,
|
|
|
|
LoggerPro.SimpleConsoleAppender;
|
|
|
|
|
|
|
|
const
|
|
|
|
MAX_TASK = 5;
|
|
|
|
var
|
2023-10-18 16:25:23 +02:00
|
|
|
lTasks: array of ITask;
|
|
|
|
lLog: ILogWriter;
|
2023-02-27 12:26:25 +01:00
|
|
|
begin
|
2023-10-18 16:25:23 +02:00
|
|
|
lLog := BuildLogWriter([TLoggerProSimpleConsoleAppender.Create]);
|
2023-02-27 12:26:25 +01:00
|
|
|
|
2023-10-18 16:25:23 +02:00
|
|
|
Setlength (lTasks, MAX_TASK);
|
2023-02-27 12:26:25 +01:00
|
|
|
for var i := 0 to MAX_TASK - 1 do begin
|
2023-10-18 16:25:23 +02:00
|
|
|
lTasks[i] := TTask.Create(procedure
|
2023-02-27 12:26:25 +01:00
|
|
|
var
|
|
|
|
I: Integer;
|
|
|
|
lThreadID: string;
|
|
|
|
begin
|
|
|
|
lThreadID := TTask.CurrentTask.Id.ToString;
|
|
|
|
for I := 1 to 200 do
|
|
|
|
begin
|
2023-10-18 16:25:23 +02:00
|
|
|
lLog.Debug('log message ' + TimeToStr(now) + ' ThreadID: ' + lThreadID, 'MULTITHREADING');
|
|
|
|
lLog.Info('log message ' + TimeToStr(now) + ' ThreadID: ' + lThreadID, 'MULTITHREADING');
|
|
|
|
lLog.Warn('log message ' + TimeToStr(now) + ' ThreadID: ' + lThreadID, 'MULTITHREADING');
|
|
|
|
lLog.Error('log message ' + TimeToStr(now) + ' ThreadID: ' + lThreadID, 'MULTITHREADING');
|
|
|
|
lLog.Fatal('log message ' + TimeToStr(now) + ' ThreadID: ' + lThreadID, 'MULTITHREADING');
|
2023-02-27 12:26:25 +01:00
|
|
|
end;
|
|
|
|
end);
|
2023-10-18 16:25:23 +02:00
|
|
|
lTasks[i].Start;
|
2023-02-27 12:26:25 +01:00
|
|
|
end;
|
|
|
|
|
2023-10-18 16:25:23 +02:00
|
|
|
TTask.WaitForAll(lTasks);
|
2023-02-27 12:26:25 +01:00
|
|
|
end.
|