quarta-feira, 2 de setembro de 2009

Função para gerar log de errosFunção para gerar log de erros

Function SaveLogError(Const AUnitError, ASimbolError, ADescription, ATypeError, ASQLError, AInsError: string): integer;
var
VMemory: TMemoryStatus;
VLogFile: TextFile;
VLogFileName: string;
vcount : Integer;
begin
VMemory.dwLength := SizeOf(TMemoryStatus);
GlobalMemoryStatus(VMemory);
VLogFileName := format('%spdferror.log',[GPathFile]);
try
AssignFile(VLogFile,VLogFileName);
if FileExists(VLogFileName) then
begin
Append(VLogFile);
Writeln(VLogFile,'');
Writeln(VLogFile,'mensagem');
Writeln(VLogFile,'');
end
else
begin
Rewrite(VLogFile);
Writeln(VLogFile,'CABTEC - Soluções em códigos de barras');
Writeln(VLogFile,format('Fone %s - E-Mail: cabtec@cabtec.com.br','(0xx31)3295-0555']));
Writeln(VLogFile,'Rua Araguari, nº 358/16º andar - Barro Preto');
Writeln(VLogFile,'20190-110 - Belo Horizonte - MG');
Writeln(VLogFile,'mensagem');
Writeln(VLogFile,'');
end;
Writeln(VLogFile,format('DATE/TIME............: %s',[DateTimeToStr(Now)]));
Writeln(VLogFile,format('Unit Error...........: %s',[AUnitError]));
Writeln(VLogFile,format('Call Symbol..........: %s',[ASimbolError]));
Writeln(VLogFile,format('Error type...........: %s',[ATypeError]));
Writeln(VLogFile,format('Description..........: %s',[ADescription]));
Writeln(VLogFile,format('SQL Error............: %s',[ASQLError]));
Writeln(VLogFile,format('Instruction error....: %s',[AInsError]));
Writeln(VLogFile,'');
Writeln(VLogFile,format('Memory free..........: %.0f bytes',[(VMemory.dwAvailPhys / 1024)])); // bytes livres de memória física
Writeln(VLogFile,format('Total PageFile.......: %.0f
bytes',[(VMemory.dwTotalPageFile / 1024)])); // bytes livres de paginação de arquivo // bytes de paginação de arquivo
Writeln(VLogFile,format('Avail PageFile.......: %.0f
bytes',[(VMemory.dwAvailPageFile / 1024)])); // bytes em uso de espaço de endereço
Writeln(VLogFile,format('Total Virtual .......: %.0f
bytes',[(VMemory.dwTotalVirtual / 1024)]));
Writeln(VLogFile,format('Avail virtual free...: %.0f
bytes',[(VMemory.dwAvailVirtual / 1024)])); // bytes livres
CloseFile(VLogFile);
result := IOResult;
except
result := IOResult;
result := -1;
end;
end; Use assim:

try
Post;
result := True;
except
on E: Exception do
begin
SaveLogError('Unit_nota','function TForm_Nota.SetSaveItensData: boolean', E.Message, E.ClassName, '', 'Post');
Application.MessageBox('Ocorreu um erro ao gravar os dados na tabela de ITENS!',CCAPTIONAPPLICATIONTITLE,mb_Ok + mb_IconStop + mb_DefButton1 + mb_applmodal);
Cancel;
result := False;
break;
end;
end;

Nenhum comentário:

Postar um comentário