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

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



