I have the following piece of code that works well in Windows Server 2003. It writes to the Application Event Log in EventViewer. The same code doesn't work in Windows 2008. The application crashes. Request to help on how to write to event log in Windows Server 2008.
if (!EventLog.SourceExists("MyServiceLog"))
{
EventLog.CreateEventSource("MyServiceLog", "Application");
}
//Create an EventLog instance and assign its source.
EventLog eventLog = new EventLog();
eventLog.Source = "MyServiceLog";
//Write an informational entry to the event log.
eventLog.WriteEntry(Header + ": " + FailureReason);