destructor TTracer.Destroy; begin if FOutput <> nil then FOutput := nil; inherited; end; procedure TTracer.SetOutput(const Value: IOutput); begin FOutput := Value; end; procedure TTracer.Write(const aInfo: ITraceInfo); begin if FOutput = nil then raise Exception.CreateFmt('没有创建输出目标%s!!!', []); FOutput.Write(aInfo); end; { TStringTI } constructor TStringTI.Create(data: string); begin FData := Data; end; function TStringTI.ToString: string; begin Result := FData; end; { TStringLog } constructor TFileLog.Create(const FileName: string); begin FLogFile := FileName; end; procedure TFileLog.Write(const aInfo: ITraceInfo); begin if not FileExists(FLogFile) then FileClose(FileCreate(FLogFile)); with TStringList.Create do begin try LoadFromFile(FLogFile); Add(aInfo.ToString); SaveToFile(FLogFile); finally Free; end; end; end; |