Retrofitting Windows Event Log to a Delphi 5 app

后端 未结 4 1930
慢半拍i
慢半拍i 2021-01-01 04:56

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

4条回答
  •  余生分开走
    2021-01-01 06:00

    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.

    1. 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;

    2. Create an instance of the logger.

      MyEventLog := TEventLogger.Create('MyApplication');

    3. To write to the event log:

      MyEventLog.LogMessage('MyApplication started.'), EVENTLOG_INFORMATION_TYPE);

    4. 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:

提交回复
热议问题