Skip to content

Commit

Permalink
feat: add exception to save file
Browse files Browse the repository at this point in the history
  • Loading branch information
dliocode committed Oct 10, 2024
1 parent 87ea239 commit 6ba11a5
Showing 1 changed file with 95 additions and 31 deletions.
126 changes: 95 additions & 31 deletions src/Providers/DataLogger.Provider.TextFile.pas
Original file line number Diff line number Diff line change
Expand Up @@ -273,44 +273,104 @@ procedure TProviderTextFile.Save(const ACache: TArray<TLoggerItem>);

Break;
except
on E: Exception do
begin
Inc(LRetriesCount);

Sleep(50);

if Assigned(FLogException) then
FLogException(Self, ACache[0], E, LRetriesCount);

if Self.Terminated then
Exit;

if (LRetriesCount <= 0) then
Break;

if (LRetriesCount >= FMaxRetries) then
Break;
end;
end;

FCleanOnRun := True;
end;

LRetriesCount := 0;

while True do
try
CreateWriter;
Break;
except
on E: Exception do
begin
Inc(LRetriesCount);

Sleep(50);

if Assigned(FLogException) then
FLogException(Self, ACache[0], E, LRetriesCount);

if Self.Terminated then
Exit;

if (LRetriesCount <= 0) then
Break;

if (LRetriesCount >= FMaxRetries) then
raise;
Break;
end;
end;

FCleanOnRun := True;
end;

CreateWriter;
try
for LItem in ACache do
begin
if LItem.InternalItem.IsUndoLast then
try
for LItem in ACache do
begin
UndoLast;
Continue;
end;
if LItem.InternalItem.IsUndoLast then
begin
UndoLast;
Continue;
end;

if LItem.InternalItem.IsSlinebreak then
LLog := ''
else
LLog := SerializeItem.LogItem(LItem).ToString;

LRetriesCount := 0;

while True do
try
InternalWriteLog(LLog);
Break;
except
on E: Exception do
begin
Inc(LRetriesCount);

if LItem.InternalItem.IsSlinebreak then
LLog := ''
else
LLog := SerializeItem.LogItem(LItem).ToString;
Sleep(50);

InternalWriteLog(LLog);
if Assigned(FLogException) then
FLogException(Self, LItem, E, LRetriesCount);

if (FMaxFileSizeInKiloByte > 0) then
if (FWriter.BaseStream.Size > (FMaxFileSizeInKiloByte * 1024)) then
RotateLog;
if Self.Terminated then
Exit;

if (LRetriesCount <= 0) then
Break;

if (LRetriesCount >= FMaxRetries) then
Break;
end;
end;

if (FMaxFileSizeInKiloByte > 0) then
if (FWriter.BaseStream.Size > (FMaxFileSizeInKiloByte * 1024)) then
RotateLog;
end;
finally
FreeWriter;
end;
finally
FreeWriter;
end;
end;

function TProviderTextFile.GetLogFileName(const AFileNumber: Int64): string;
Expand Down Expand Up @@ -495,16 +555,20 @@ procedure TProviderTextFile.ZipFile(const ADirFileName: string; const AFileName:
var
LRemoveLogFileName: Boolean;
begin
LRemoveLogFileName := True;
try
LRemoveLogFileName := True;

if Assigned(FCompressCustom) then
FCompressCustom(ADirFileName, AFileName, LRemoveLogFileName)
else
CreateZipFile(ADirFileName, AFileName);
if Assigned(FCompressCustom) then
FCompressCustom(ADirFileName, AFileName, LRemoveLogFileName)
else
CreateZipFile(ADirFileName, AFileName);

if LRemoveLogFileName then
if TFile.Exists(ADirFileName) then
TFile.Delete(ADirFileName);
if LRemoveLogFileName then
if TFile.Exists(ADirFileName) then
TFile.Delete(ADirFileName);
except

end;
end)
.Start;
end;
Expand Down

0 comments on commit 6ba11a5

Please sign in to comment.