【问题标题】:Creating a Custom Event Log (Security Error)创建自定义事件日志(安全错误)
【发布时间】: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


【解决方案1】:

要创建事件源,您必须具有管理权限。

必须搜索所有事件日志,包括安全日志,以确定事件源是否唯一。非管理用户无权访问安全日志,因此会引发 SecurityException。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-11
    • 2012-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多