Title: How to produce Logfile-Data from your Application
Question: You needs Logfile data from selected point at your application.
The Logfile.txt is stored in the Applications path. This produces
separate Logfiles for every Application.
Answer:
create a procedure to do this
procedure MyLog(const MyText: string; MyFormat: array of const);
var
F: TextFile;
LogFileName: string;
begin
// set the Logfile-Name and assign it
LogFileName := ExtractFilePath(ParamStr(0)) + 'Logfile.txt';
AssignFile(F, LogFileName);
// see if file exists then append new record
// else write it new
if FileExists(LogFileName) then
Append(F)
else
Rewrite(F);
// first write a Date-Time-stamp to identify this Log-Entry
Write(F, DateToStr(date) + ' ' + TimeToStr(Time) + ' ');
// and then write MyText formatted with MyFormat-Arguments
WriteLn(F, Format(MyText, MyFormat));
CloseFile(F);
end;
// calling samples:
// 1. with one value
myLog('EingabeX FormCreate: LocateKunde=%d', [iKunde]);
// 2. with many values
MyLog('DecodeDate: iYear=%d, iMonth=%d, iDay=%d', [iYear, iMonth, iDay]);
// you can use many Arguments and all normal formats (see help Format)
Here a Sample of Logfile.txt:
31.08.2001 14:28:54 EingabeX FormCreate: LocateKunde=357
31.08.2001 14:28:54 DecodeDate: iYear=2001, iMonth=8, iDay=31
Regards
Kurt