【发布时间】:2015-01-16 20:37:30
【问题描述】:
我正在尝试使用以下代码创建自己的自定义事件日志:
if (!System.Diagnostics.EventLog.SourceExists("DataStream"))
{
EventLog.CreateEventSource("DataStream", "SIRsDetectionDataStreamLog");
}
logger = new EventLog();
logger.Source = "DataStream";
但是,在检查源是否存在时,我不断收到安全错误。我得到的错误如下:
SecurityException was unhandled
An unhandled exception of type 'System.Security.SecurityException' occurred in System.dll
Additional information: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.
【问题讨论】:
-
阅读文档:msdn.microsoft.com/en-us/library/vstudio/…。
SecurityException: source was not found, but some or all of the event logs could not be searched。即您需要成为管理员。 -
考虑在安装服务时创建事件日志。您必须是管理员才能安装服务。您可以在服务安装程序中使用 EventLogInstaller 或在您的 MSI 中使用类似 WiX 的 EventSource 组件。
标签: c# security windows-services event-log