SourceExists方法时问题

SourceExists方法时问题

本文介绍了试图在.NET中使用EventLog.SourceExists方法时问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用使用C#在我的应用eventlogs,所以我增加了以下code

I am trying to use eventlogs in my application using C#, so I added the following code

if (!EventLog.SourceExists("SomeName"))
EventLog.CreateEventSource("SomeName", "Application");

在EventLog.SourceExists导致SecurityException异常,说
该人士未找到,但全部或部分事件日志不能被搜索无法访问的日志:。安全

The EventLog.SourceExists causes SecurityException that says
"The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security."

我以管理员身份运行在Windows 7中。

I am running as administrator in Windows 7.

任何帮助将appriciated。

Any help would be appriciated.

推荐答案

这是一个权限的问题 - 你应该给正在运行的用户权限读取以下注册表项:

This is a permissions problem - you should give the running user permission to read the following registry key:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\EventLog

Alternaitvely可以bypas的为CreateEventSource 不再需要访问此注册表项。

Alternaitvely you can bypas the CreateEventSource removing the need to access this registry key.

这两种解决方案中更详细在下面的螺纹解释 - How做我创建一个事件日志源在Vista?。

Both solutions are explained in more detail in the following thread - How do I create an Event Log source under Vista?.

这篇关于试图在.NET中使用EventLog.SourceExists方法时问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 13:54