c# - 找不到来源,但无法搜索到部分或所有事件日志

标签 c# .net windows-7 event-log securityexception

我收到以下异常。我已在注册表编辑中的事件日志上完全控制 Asp.net 帐户。

[SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.]

System.Diagnostics.EventLog.FindSourceRegistration(String source,  String machineName, Boolean readOnly, Boolean wantToCreate) +664
System.Diagnostics.EventLog.SourceExists(String source, String machineName, Boolean wantToCreate) +109
System.Diagnostics.EventLog.SourceExists(String source) +14 Microsoft.ApplicationBlocks.ExceptionManagement.DefaultPublisher.VerifyValidSource() +41

我猜这是由于服务器上的某些配置问题造成的?

最佳答案

EventLog.SourceExists 枚举 HKLM\SYSTEM\CurrentControlSet\services\eventlog 的子项,看它是否包含具有指定名称的子项。如果运行代码的用户帐户在找到目标源之前没有对其尝试访问的子项(在您的情况下为 Security 子项)的读取权限,您将看到异常就像你描述的那样。

处理此类问题的常用方法是 register event log sources在安装时(在管理员帐户下),然后假定它们在运行时存在,如果目标事件日志源在运行时实际上不存在,则允许将任何由此产生的异常视为意外。

关于c# - 找不到来源,但无法搜索到部分或所有事件日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9564420/

相关文章:

.net - 在单独运行或在 reSharper 或 TeamCity 中运行的 nUnit 中使用 Console.Out.WriteLine 与 Trace.WriteLine

ffmpeg - TCL 命令提示符在 tcl 版本 8.0 和窗口 7 中崩溃,出现错误 "ffmpeg.exe stopped working"

windows-7 - 路由表 Windows 7

c# - 使用 HAP (HTML Agility Pack) 从页面获取数据

c# - 在 C# 中的 BouncyCaSTLe 中构建证书链

c# - .NET 控制台的窗口系统

windows-7 - IIS 7 管理器未打开但正在工作

c# - 所有系统的循环是否以相同的速度发生?

.net - 从 .Net 枚举另一个应用程序的 Windows/控件

c# - 绑定(bind) DataGridView 中的组合框