2

我知道 EventLog 能够将异常消息写入磁盘上的日志中。我已经设法设置了组件,但是当我将组件设置为活动并进行简单的测试时,例如:

eventlog.Debug('Application has started!');

我收到以下异常:

事件日志处于活动状态时不允许操作。

我究竟做错了什么 ?即使我将 RaiseExceptionOnError 设置为 true,我也无法在日志中找到异常。

请一个简单的示例用法会很棒!

4

2 回答 2

2

Minimal working sample: A Form with two buttons and one eventlog.

Code (change $Username):

procedure TForm1.Button1Click(Sender: TObject);
begin
  EventLog1.LogType := ltFile;
  EventLog1.FileName := 'C:\users\$USERNAME\Desktop\Test.log';
  EventLog1.Active := True;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  EventLog1.Debug('This is a test.');
end;   

Click first on Button1, then on Button2. Have fun.

于 2013-09-25T12:23:35.553 回答
2

如果您想自动记录异常,请查看http://wiki.freepascal.org/Logging_exceptions#Handling_exceptions

于 2013-09-26T06:58:31.293 回答