我收到以下异常。我已在注册表编辑中的事件日志上完全控制 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/