2

I'm trying to write an windows log event.

I read this answer, and tried to use it but had the same problem reported here "The description for Event ID 1 from source PLCHIDSrv cannot be found..."

I'm trying this solution but do not know how to implement this code in Delphi

var data = new EventSourceCreationData("yourApp", "Application");
data.MessageResourceFile = pathToYourMessageFile;
EventLog.CreateEventSource(data);
Community
  • 1
  • 1
MarcosK
  • 31
  • 6
  • 1
    You can use Google to find loads of hits. For instance: http://rosettacode.org/wiki/Write_to_Windows_event_log#Delphi http://texhex.blogspot.co.uk/2004/09/creating-event-message-file-for-event.html http://www.kehm.de/henrik/blog/files/0246b791a5cc7befdf178875d4e318c8-2.html and of course you can read the MS documentation on MSDN – David Heffernan Oct 29 '14 at 20:55
  • 1
    The answer to this question should solve your problem http://stackoverflow.com/questions/10537267/delphi-windows-service-design - Specifically point 5 has the code to create the registry entries. – Graymatter Oct 29 '14 at 21:48

1 Answers1

9

You are receiving that error because you are not adding the event source to the Windows Registry.

Check the MSDN Documentation :

You can use the default Application log without adding an event source to the registry. However, Event Viewer will not be able to map your event identifier codes to message strings unless you register your event source and provide a message file.

The same link contains a sample with a C++ Code , which can be easily translated to Delphi.

UPDATE

I just found this article Writing an event logger with Delphi 2010 which shows how add an event source to the registry and write to the event log.

RRUZ
  • 134,889
  • 20
  • 356
  • 483