我知道 EventLog 能够将异常消息写入磁盘上的日志中。我已设法设置该组件,但是当我将组件设置为事件状态并执行如下简单测试时:
eventlog.Debug('Application has started!');
我收到以下异常:
事件日志处于事件状态时不允许进行操作。
我做错了什么?即使我将 RaiseExceptionOnError 设置为 true,我也无法在日志中找到异常。
请提供一个简单的示例用法就太好了!
最佳答案
最小工作示例:带有两个按钮和一个事件日志的表单。
代码(更改$用户名):
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;
首先单击“Button1”,然后单击“Button2”。玩得开心。
关于freepascal - 在lazarus中使用TEventLog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19001357/