델파이

델파이/Delphi] 프로그램 로그(LOG) 생성 방법

il-ma-re 2024. 7. 12. 09:18
728x90

안녕하세요, 일마레입니다.

 

개발을 하고 운영을 하다 보면 에러가 발생할 경우가 생기는데 

빠른 수정을 위해 생성 해놓은 로그를 보면서 처리하고 있습니다.

 

어떤 작업 혹은 상황이었는지 로그를 만들어 놓으면 

빠른 확인 및 처리가 가능하기에 사용하고 있습니다.


public 
 gsLogFile  : string;

procedure Log(ALog: string);var  hFile: TextFile;
begin
  if VarIsNull(gsLogFile) then
    gsLogFile := ExtractFilePath(Application.ExeName)+'log\'+FormatDateTime('yyyymmdd', Now)+'.log';

  try
    AssignFile(hFile, gsLogFile);
    try
      if FileExists(gsLogFile) then Append(hFile)
      else Rewrite(hFile);
      WriteLn(hFile, '['+DateTimeToStr(Now)+']  '+ALog);
    except
    end;
  finally
    CloseFile(hFile);
  end;
end;

 

확인해 보시고 사용해보세요!

728x90
LIST