C# EventLog 无法访问日志

发布于 2024-12-26 06:12:41 字数 531 浏览 1 评论 0原文

下面是我在运行下面的代码时遇到的异常:

未找到源,但无法搜索部分或全部事件日志。无法访问的日志:安全性。

代码是

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

异常的内容对我来说有意义,这就是为什么它没有意义。该行在 Visual Studio 2010、.NET 4 中作为控制台应用程序运行(暂时)。我已经在不同的环境中运行了这个,但我不希望我远程桌面会破坏这个方法。我尝试更改 HKML\CCS\Services\eventlog 权限 - 无济于事,以及 C:\Windows\System32\Winevt\Logs\Security.evtx权限。再次,无济于事。

我的问题如下:

  1. 为什么没有覆盖来忽略安全日志,
  2. 我如何解决这个问题(以编程方式)
  3. 这是因为我是远程桌面。

任何建议都会很棒。

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.

The code is

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

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.

My questions are as follows:

  1. Why isn't there an override to ignore secure logs,
  2. How can I work around this ( programatically )
  3. IS this because I'm remote desked.

Any advice would be great.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

探春 2025-01-02 06:12:41

出于您所发现的原因,Microsoft 要求您成为管理员才能执行此方法。

以下是他们的解释(来自MSDN 文档):

要在 Windows Vista 及更高版本或 Windows Server 2003 中搜索事件源,您必须具有管理权限。

此要求的原因是必须搜索所有事件日志(包括安全性)以确定事件源是否唯一。从Windows Vista开始,用户无权访问安全日志;因此,会抛出 SecurityException。

您如何解决这个问题完全取决于您需要做什么。如果您无法以管理员身份登录,最好的建议是尝试在 try/catch 块中执行操作,如果抛出 SecurityException,则执行一些替代操作。

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

Here is their explanation (from the MSDN documentation):

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

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.

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.

蛮可爱 2025-01-02 06:12:41

访问某些事件日志需要提升权限。请以管理员身份运行该应用程序。

Accessing some EventLogs requires elevation. Run the app as an administrator instead.

丶情人眼里出诗心の 2025-01-02 06:12:41

我建议使用 企业库,以便实现正确的日志记录。

此处开始阅读

I recommend to use Logging Application Block of Enterprise Library in order to implement the correct logging.

Start reading from here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文