- Delphi Cookbook
- Daniele Spinetti Daniele Teti
- 208字
- 2025-04-04 16:22:46
Using the TService.LogMessage method
If something happens during the execution of the service that you want to log, and you want to log in to the system logger, you can use the LogMessage method to save a message. The message can be viewed later using the Windows built-in event viewer.
You can call the LogMessage method using an appropriate logging type, like this:
LogMessage('Your message goes here for SUCCESS',
EVENTLOG_SUCCESS, 0, 1);
If you check the event in the Event Viewer, you will find a lot of garbage text that complains about the lack of description for the event.
If you really want to use the Event Viewer to view your log message (when I can, I use a logfile and don't concern myself with the Event Viewer, but there are scenarios where the Event Viewer log is needed), you have to use the Microsoft ? Message Compiler.
The Microsoft ? Message Compiler is a tool able to compile a file of messages into a set of RC files. Then, these files must be compiled by a resource compiler and linked into your executable.
More information on Microsoft ? Message Compiler and the steps needed to provide the description for the log event can be found at http://www.codeproject.com/Articles/4166/Using-MC-exe-message-resources-and-the-NT-event-lo.