Spring4D 的日志记录机制是线程安全的吗?(单位 Spring.Logging.*,我想)
例如,多个线程可以解析并使用ILogger
来自以下容器的实现吗?
uses
System.SysUtils,
Spring.Container,
Spring.Logging,
Spring.Logging.Appenders,
Spring.Logging.Controller,
Spring.Logging.Loggers;
var
Container: TContainer;
TextLogAppender: TTextLogAppender;
FileLogAppender: TFileLogAppender;
LoggerController: TLoggerController;
LoggerInThread1: ILogger;
LoggerInThread2: ILogger;
begin
TextLogAppender := TTextLogAppender.Create;
FileLogAppender := TFileLogAppender.Create;
FileLogAppender.FileName := 'Log.txt';
LoggerController := TLoggerController.Create;
LoggerController.AddAppender(TextLogAppender as ILogAppender);
LoggerController.AddAppender(FileLogAppender as ILogAppender);
Container := TContainer.Create;
try
Container.RegisterInstance<ILoggerController>(LoggerController);
Container.RegisterType<ILogger, TLogger>;
Container.Build;
LoggerInThread1 := Container.Resolve<ILogger>;
LoggerInThread2 := Container.Resolve<ILogger>;
{$Region 'threaded code'}
LoggerInThread1.Info('Hello from Thread 1!');
LoggerInThread2.Info('Hello from Thread 2!');
{$EndRegion}
finally
Container.Free;
end;
end;
使用分支release/1.2(当前为 33e3232...)。