C# EventLog 无法访问日志
下面是我在运行下面的代码时遇到的异常:
未找到源,但无法搜索部分或全部事件日志。无法访问的日志:安全性。
代码是
if (!EventLog.SourceExists(this.EventLogSource))
异常的内容对我来说有意义,这就是为什么它没有意义。该行在 Visual Studio 2010、.NET 4 中作为控制台应用程序运行(暂时)。我已经在不同的环境中运行了这个,但我不希望我远程桌面会破坏这个方法。我尝试更改 HKML\CCS\Services\eventlog 权限 - 无济于事,以及 C:\Windows\System32\Winevt\Logs\Security.evtx
权限。再次,无济于事。
我的问题如下:
- 为什么没有覆盖来忽略安全日志,
- 我如何解决这个问题(以编程方式)
- 这是因为我是远程桌面。
任何建议都会很棒。
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:
- Why isn't there an override to ignore secure logs,
- How can I work around this ( programatically )
- IS this because I'm remote desked.
Any advice would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
出于您所发现的原因,Microsoft 要求您成为管理员才能执行此方法。
以下是他们的解释(来自MSDN 文档):
您如何解决这个问题完全取决于您需要做什么。如果您无法以管理员身份登录,最好的建议是尝试在 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):
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.
访问某些事件日志需要提升权限。请以管理员身份运行该应用程序。
Accessing some EventLogs requires elevation. Run the app as an administrator instead.
我建议使用 企业库,以便实现正确的日志记录。
从此处开始阅读
I recommend to use Logging Application Block of Enterprise Library in order to implement the correct logging.
Start reading from here