I\'m looking for a (fairly pain-free) means of adding some Windows Application Event-Log support to a small legacy Delphi 5 application. We just want it to log when it start
I use standard VCL for this in Delphi 6, I can't tell you whether or not this is available in Delphi 5. Try it for yourself and let us know if this stuff is there in D5.
Declare a global/form variable of type TEventLogger. This is declared in the SvcMgr unit so this unit will need to be added to your uses list. If this is a normal application (i.e. not a Service) then make sure SvcMgr is added after the Forms unit.
MyEventLog: TEventLogger;
Create an instance of the logger.
MyEventLog := TEventLogger.Create('MyApplication');
To write to the event log:
MyEventLog.LogMessage('MyApplication started.'), EVENTLOG_INFORMATION_TYPE);
Don't forget to release it at the end:
MyEventLog.Free;
There is other stuff you need to do to register the application with the Windows Event Log so that the message appears without this in front of it:
The description for Event ID ( 1000 ) in Source ( Microsoft Internet Explorer ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. The following information is part of the event: