[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

Dumping Error Notifications to text files

I want to write the time and message of Delphi Error Notifications, to say a text file, and then programmatically kill the application - any hints on how to acheive this?
Tx
0
VEEPROG
Asked:
VEEPROG
  • 2
1 Solution
 
geobulCommented:
TForm1 is the main form of the app:

TForm1 = class(TForm)
  ...
  procedure FormCreate(Sender: TObject);
  procedure AppException(Sender: TObject; E: Exception);
end;
...

// Writes a line to a log file
function WriteLog(aLine: string) : boolean;
var
  FF: Text;
begin
  Result := true;
  try
    // Open the file
    AssignFile(FF, 'MyApp.log');
    if FileExists(log) then begin
      Append(FF);
    end else begin
      Rewrite(FF);
    end;
    Writeln(FF,FormatDateTime('dd.mm.yyyy hh:nn', Now) + ' ' + aLine);
    { Close file }
  finally
    CloseFile(FF);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnException := AppException;
end;

procedure TForm1.AppException(Sender: TObject; E: Exception);
begin
  WriteLog(E.Message);
  Application.Terminate;
end;

Regards, Geo
0
 
geobulCommented:
I've answered the question.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now