1、定义类型
var
F: TextFile;
Logfile: string;
txt :string;
2、代码
//创建目录
if not directoryexists(_AppPath + 'Error/') then
createdir(_AppPath + 'Error/');
LogFile := _AppPath + 'Error/' + FormatDateTim('YYYYMMDD',Date) + '.txt';
//写日志文件
AssignFile(F, LogFile);
if FileExists(LogFile) then
Append(F)
else
Rewrite(F);
//开始写入
Writeln(F, txt);
//结束
CloseFile(F);
本文介绍了一个使用Delphi进行日志记录的例子。通过创建指定目录并根据当前日期生成日志文件,实现了日志信息的追加或重写。此方法适用于需要记录程序运行状态的应用场景。
2880

被折叠的 条评论
为什么被折叠?



