Adding appender to LogWriter by AddAppender procedure log twice.
procedure TCustomLogWriter.AddAppender(const aAppender: ILogAppender);
begin
Self.FLoggerThread.FAppenders.Add(aAppender);
Self.FLogAppenders.Add(aAppender);
Self.FLoggerThread.FAppendersDecorators.Add(TLoggerThread.TAppenderAdapter.Create(aAppender));
end;
Duplicate is caused by the first line of the procedure Self.FLoggerThread.FAppenders.Add(aAppender); because Self.FLogAppenders is passed to Self.FLoggerThread so both are the same List.
Access violation occurs because Self.FLoggerThread.FAppendersDecorators is nil till the first Thread Execute.
Here is the modified version:
procedure TCustomLogWriter.AddAppender(const aAppender: ILogAppender);
begin
Self.FLogAppenders.Add(aAppender);
if Assigned( Self.FLoggerThread.FAppendersDecorators) then
Self.FLoggerThread.FAppendersDecorators.Add(TLoggerThread.TAppenderAdapter.Create(aAppender));
end;
Adding appender to LogWriter by AddAppender procedure log twice.
Duplicate is caused by the first line of the procedure
Self.FLoggerThread.FAppenders.Add(aAppender);
becauseSelf.FLogAppenders
is passed toSelf.FLoggerThread
so both are the same List.Access violation occurs because
Self.FLoggerThread.FAppendersDecorators
isnil
till the first Thread Execute.Here is the modified version: