我有以下在 Windows Server 2003 中运行良好的代码。它写入 EventViewer 中的应用程序事件日志。相同的代码在 Windows 2008 中不起作用。应用程序崩溃。请求有关如何在 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);