AddAppender raises AccessViolation and duplicates appenders
vveliu-csw opened this issue · 2 comments
vveliu-csw commented
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;
danieleteti commented
vveliu-csw commented
@danieleteti U Welcome!
Related to the argument i opened a new Issue #70