Delph记录输出日志


本文整理自网络,侵删。

 
Delphi程序在运行着,有时想获取一些程序运行的值的话,可以用下面的输出日志的函数来实现

procedure WriteLog(sContent: string); //写入日志

var

tFile: TextFile;

filename: string;

logDir:string;

begin

logDir:='log';

filename := ExtractFilePath(Application.ExeName) + logDir+'\'+ FormatDateTime('yyyyMMdd', Now) + '.txt';

if not DirectoryExists(ExtractFilePath(Application.ExeName) + logDir) then

begin

MkDir(ExtractFilePath(Application.ExeName) + logDir);

end;


AssignFile(tFile, filename);

if FileExists(filename) then

Append(tFile)

else

Rewrite(tFile);

Writeln(tFile, FormatDateTime('yyyy-MM-dd hh:nn:ss', Now)+' '+sContent);

CloseFile(tFile);

end;

只要在想在调试的地址写上 writeLog('输出的内容'); 这样就可以在软件所在目录下的log目录里生成的TXT文件里查看信息.

相关阅读 >>

Delphi汇编级初探

Delphi xe 关闭android应用

Delphi 连接dbf数据

tidhttpresponseinfo 中文乱码问题解决

解决 Delphi 程序在不同操作系统中 shellexecute 调用 chrome.exe 偶尔无效的问题

Delphi 计算一个路径相对于另一路径的相对路径

Delphi richedit根据鼠标位置定位光标的方法

Delphi insert 插入一个字符(串)

Delphi 创建自己的定时器 定时清理内存

Delphi enumwindows回调函数获取qq2009窗体句柄

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



打赏

取消

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

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

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

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

评论

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