Delphi实用小function

Write Log

    // strLog : the log content need write to log file;
    // strFile: the compliete file path(include the file name) of the log file. e.g. C:\log.log;
    procedure WriteLog(strLog, strFile: string);
    var
       fLog: TextFile;
    begin
       AssignFile(fLog, strFile);
       try
          if FileExists(strFile) then
            Append(fLog)
         else
            Rewrite(fLog);
    
         //ready to write log content
         Writeln(fLog,Format('%s -> %s', [FormatDateTime('hh:mm:ss',now()), strLog]) );
      finally
         CloseFile(fLog);
      end;
   end;
posted @ 2013-11-14 16:47  LARSON _  Views(245)  Comments(0Edit  收藏  举报