1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| procedure FichierLog(Fichier, Titre, BufferLog: String);
var
LogFile: File; //TextFile;
NameFile, TimeLog: String;
Buf: String;
const
LogDir = 'Log\';
LogName = 'LOG_';
LogExt = '.txt';
begin
// C:\...\MonProgramme.exe -> C:\...\MonProgramme\log\
try
TimeLog := FormatDateTime('dd/mm/yyyy hh:nn:ss:zzz',Now()) ;
NameFile := ExtractFilePath(Application.ExeName) + LogDir + ChangeFileExt(ExtractFileName(Application.ExeName), '\');
if not DirectoryExists(NameFile) then begin
ForceDirectories(NameFile);
end;
NameFile := NameFile + LogName + Fichier + LogExt;
try
AssignFile(LogFile, NameFile);
try
if not FileExists(NameFile) then begin
ReWrite(LogFile, 1);
end else begin
// Append(LogFile);
Reset(LogFile, 1);
Seek(LogFile, FileSize(LogFile));
end;
try
Buf := TimeLog + #9', ' + Titre+' :'#9+ BufferLog+#13#10;
// Buf[1] car BlockWrite écrit n octets à partir de la position Buf[1] !
BlockWrite(LogFile, Buf[1], Length(Buf));
// Write(LogFile, TimeLog + #9', ' + Canal+' :'#9+ BufferLog+#13#10) ;
except
Exit;
end;
finally
CloseFile(LogFile);
end;
except
Exit;
end ;
except
Exit;
end ;
end; |
Partager