delphi怎样写一个程序的日志啊?

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);


来源: http://www.programbbs.com/bbs/view12-4986-1.htm

你可能感兴趣的:(delphi怎样写一个程序的日志啊?)