簡體   English   中英

找不到源“y”中事件 ID“x”的描述。 從 eventvwr C# 讀取“系統”事件日志

[英]The description for Event ID 'x' in Source 'y' cannot be found. Reading 'System' event logs from eventvwr C#

我有一小段代碼可以從 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

我以管理員身份運行此代碼。

誰能幫我弄清楚為什么我會收到此類消息進行描述。 提前致謝

有類似的帖子,但沒有一個提出這個問題。 例如這個

“找不到源 Y 中事件 ID X 的描述。”

作為管理員,您要么無權訪問消息文件,要么其位置不在您當前的路徑上。

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

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

您應該找到一個 Value EventMessageFile ,其中包含數據%systemroot%\\system32\\microsoft-windows-kernel-power-events.dll或類似文件 - 這是來自我的機器。

以管理員身份檢查這是否在您的路徑上以及您擁有哪些權限。

關於 C# 的主題,但如果您在 PowerShell 中遇到此錯誤,只需切換到使用Get-WinEvent而不是 Get-EventLog,一切都會好起來的。


來源: Boe Prox 在此處的回復:

使用 Get-WinEvent 代替 [...] Get-EventLog 更適合舊操作系統。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM