本文整理自网络,侵删。
Uses Sysutils, FileCtrl{, System};procedure WriteRunlog(sLogStr: string; sPath:string=''; sFileName: string='');var F: TextFile; sNow : string;begin //路径及文件名处理 sNow := FormatDateTime('yyyy.mm.dd HH:NN:ss ', Now); if Trim(sPath) = '' then sPath := ExtractFileDir(ParamStr(0)) + '\Log\'; if not DirectoryExists(sPath) then MkDir(sPath); if Trim(sFileName) = '' then sFileName := sPath + 'RunLog'+ FormatDateTime('yyyymmdd', Date)+ '.txt' else sFileName := sPath + sFileName;
//开始写文件 AssignFile(F, sFileName); try if FileExists(sFileName) then Append(F) else Rewrite(F); Writeln(F, sNow+ sLogStr); finally CloseFile(F); end;end;
相关阅读 >>
Delphi http 常见异常状态及Delphi idhttp 控件处理方式
Delphi 从indy9升级到indy10时idtcpserver的变化
更多相关阅读请进入《Delphi》频道 >>