我有以下一段代码,在Windows Server 2003中运行良好。它在EventViewer中写入应用程序事件日志。相同的代码在Windows 2008中不起作用。应用程序崩溃。请求帮助如何写入事件日志在Windows Server 2008中如何使用C#在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);
+1击败我我的1分钟 – 2010-10-02 12:23:59
谢谢我以管理员模式运行我的应用程序。现在它工作正常。 – Defendore 2010-10-04 08:35:34
那么,如果我的控制台应用程序旨在作为Windows服务运行?如何在启动时提升服务的权限? – Maltrap 2012-11-30 00:22:22