Below is the code I use to initialize the event log, and below that is a sample line of code I use to write to the log.
private string sSource = "DaVinci";
private string sLog = "WCF WebService";
//Initialize Event Log
if(!EventLog.SourceExists(sSource)) EventLog.CreateEventSource(sSource, sLog);
//Write openining message
EventLog.WriteEntry(sSource, "Opening WCF Service", EventLogEntryType.Warning);
The program, however, is not currently writing to the log, as it's instructed to do. No messages of any kind are being written. Can anyone either see what is wrong with the above code or offer any suggestions as to where to look for the problem?
Yes, sLog should be the type of log you want to write to in the event viewer. For instance, Application
will write it to the Application log under Windows Logs.
EDIT:
It is possible you do not have permission to create the event source.
Try adding this key to your registry:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\YourSourceNameHere]
Also, if you are not running your app as Administrator, try doing so as well.