C#事件日志不可访问日志 [英] C# EventLog Inaccessible Log

查看:173
本文介绍了C#事件日志不可访问日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是在运行紧随其后的代码,我遇到一个例外:

Below is an exception I encountered while running the immediately following code:

源没有被发现,但一些或所有事件日志不能被搜索。不可访问的日志:安全性

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

代码是

if (!EventLog.SourceExists(this.EventLogSource))

的内容除了对我来说很有意义,这就是为什么没有。此行是在Visual Studio 2010,.NET 4运行,作为一个控制台应用程序(暂时)。我曾经在不同的环境中运行,但我不希望的事实,我远程desk'ed打破了这一方法。我试着改变 HKML\CCS\Services\eventlog 权限 - 无济于事,还有 C:\Windows\\ \\System32\Winevt\Logs\Security.evtx 权限。再次,不果

The content of the exception makes sense to me, it's why that doesn't. This line is running in Visual Studio 2010, .NET 4, as a console app ( for the time being ). I have run this in a different environment, but I wouldn't expect the fact that I'm remote desk'ed to break this method. I've tried changing HKML\CCS\Services\eventlog permissions - to no avail, as well as the C:\Windows\System32\Winevt\Logs\Security.evtx permissions. Again, to no avail.

我的问题如下:


  1. 为什么是不是有一个覆盖忽视安全日志,

  2. 我怎样才能解决这个(编程)

  3. 这是因为我的远程desked

任何意见将是巨大的。

推荐答案

微软要求你以执行为这个原因,你发现这种方法的管理员。

Microsoft requires that you be an administrator in order to execute this method for the very reason that you found.

下面是他们的解释(从的 MSDN文档):

Here is their explanation (from the MSDN documentation):

要搜索Windows Vista中的事件源和更高版本或Windows Server 2003,则必须具有管理员权限。

To search for an event source in Windows Vista and later or Windows Server 2003, you must have administrative privileges.

这样做的理由要求是,所有的事件日志,包括安全性,必须搜索,以确定该事件源是否是唯一的。从Windows Vista开始,用户没有权限访问安全日志;因此,抛出一个SecurityException。

The reason for this requirement is that all event logs, including security, must be searched to determine whether the event source is unique. Starting with Windows Vista, users do not have permission to access the security log; therefore, a SecurityException is thrown.

你如何解决这将完全取决于你需要做什么。如果您无法登录为管理员是试图在try / catch块执行你的行为,如果一个SecurityException被抛出,执行一些其他操作的最佳建议。

How you work around it will depend entirely on exactly what you need to do. The best recommendation if you are not able to log in as an administrator is to attempt to perform your action in a try/catch block and if a SecurityException is thrown, perform some alternate action.

这篇关于C#事件日志不可访问日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆