procedure TDebugLog.Add(text: String);
var
t: TDateTime;
f: TextFile;
begin
if (not Assigned(Self)) then
Exit;
t := Now;
EnterCriticalSection(csDL);
AssignFile(f, FName);
try
try
Append(f);
WriteLn(f, FormatDateTime('c.zzz - ', t)+text);
except
raise
Exception.Create('In DebugLog kann nicht geschrieben werden!');
end;
finally
try
CloseFile(f);
except
end;
end;
LeaveCriticalSection(csDL);
end;
constructor TDebugLog.Create(path: String);
var
i: Integer;
lastTime: TDateTime;
fn: String;
fnFound: Boolean;
f: file;
begin
inherited Create;
InitializeCriticalSection(csDL);
fnFound := false;
lastTime := 0;
for i := 1 to 5 do begin
fn := path+IntToStr(i)+'.log';
if FileExists(fn) then begin
if (lastTime > FileDateToDateTime(FileAge(fn))) then begin
fnFound := true;
break;
end else begin
lastTime := FileDateToDateTime(FileAge(fn));
end;
end else begin
fnFound := true;
break;
end;
end;
if (not fnFound) then
fn := path+'1.log';
FName := fn;
EnterCriticalSection(csDL);
AssignFile(f, FName);
try
try
Rewrite(f);
except
raise
Exception.Create('DebugLog kann nicht angelegt werden!');
end;
finally
try
CloseFile(f);
except
end;
end;
LeaveCriticalSection(csDL);
end;
destructor TDebugLog.Destroy;
begin
DeleteCriticalSection(csDL);
inherited;
end;
end.