Question

I understand that EventLog is capable into writing the exception messages into a log on disk.I have managed to setup the component, but when I set the component to active and do a simple test like:

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

I receive the following exception :

Operation not allowed when eventlog is active.

What am I doing wrong ? I can't find the exception in the log what so ever eaven if I set RaiseExceptionOnError to true.

Please a simple sample usage would be great!

Was it helpful?

Solution

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.

OTHER TIPS

If you want to auto-log exceptions, have a look at http://wiki.freepascal.org/Logging_exceptions#Handling_exceptions

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top