事件ID' x'在Source' y'无法找到。阅读'系统'来自eventvwr的事件日志C#

时间:2018-06-19 06:00:53

标签: c# windows event-viewer systemevent

我要阅读这一小段代码" System"来自eventvwr的事件

        EventLog eventLog = new EventLog("System");

        foreach (EventLogEntry log in eventLog.Entries)
        {
            Console.WriteLine("{0}\n", log.Message);
        }

这很好用,但是对于很少的事件日志,我会收到像

这样的消息
"The description for Event ID '109' in Source 'Microsoft-Windows-Kernel-Power' cannot be found.  The local computer may not have the necessary registry information or message DLL files to display the message, or you may not have permission to access them.  The following information is part of the event:'6', '0', '5'"

当我打开eventvwr时,我可以看到那里的描述。

The kernel power manager has initiated a shutdown transition.
Shutdown Reason: Kernel API

我正在以管理员身份运行此代码。

任何人都可以帮我弄清楚为什么我会收到这样的消息进行描述。提前致谢

有类似的帖子,但没有提出这个问题。例如这个

"The description for Event ID X in Source Y cannot be found."

2 个答案:

答案 0 :(得分:0)

您要么无法访问消息文件,要么其位置不在当前路径上,如管理员。

事件日志消息文件位置在注册表中定义,即如果您查看

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\System\Microsoft-Windows-Kernel-Power

你应该找到一个数据EventMessageFile或类似的值%systemroot%\system32\microsoft-windows-kernel-power-events.dll - 这是来自我的机器。

检查这是否在您的路径上,以及您拥有哪些权限,例如Admin。

答案 1 :(得分:0)

切换为使用 Get-WinEvent 而不是Get-EventLog,一切都会好的。


来源:Boe Prox's reply here:

使用Get-WinEvent代替[...] Get-EventLog更适合于较旧的操作系统。

相关问题