2017-02-17

【Delphi】寫純文字檔型式 log

 
procedure txtlog(str: string);
const
    sLogPath = 'C:\mylog.txt';
var
    logfile : TextFile;
begin
    if not FileExists(sLogPath) then
    begin
        AssignFile(logfile, sLogPath);
        ReWrite(logfile);
        CloseFile(logfile);
    end;
    AssignFile(logfile, sLogPath);
    Append(logfile);
    Writeln(logfile, FormatDateTime('yyyy/mm/dd HH:nn:ss',now)+': '+str);
    Flush(logfile);
    CloseFile(logfile);
end;