Delphi 写Log的代码(按日期)


本文整理自网络,侵删。

 

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调用rest

Delphi实现图像反色实例4种方法

android开发-px和dip以及sp的区别

Delphi添加任务栏右键菜单

Delphi 如何按下esc键退出程序

Delphi 输入法设置(imemode与imename)

Delphi中bitmap位图与base64字符串相互转换

Delphi 测试字符串读取类: tstringreader

Delphi 取得txt文件编码

Delphi 的异步方法

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...