Windows事件查看器将EventID视为16位整数(至少在WinXP中是这样),因此您可以将其强制转换为UInt16以显示与事件查看器中相同的ID. foreach(log.Entries.Cast< EventLogEntry>().Reverse()中的EventLogEntry条目){var EventID =(UInt16)entry.InstanceId;} I am looping through the event log of several remote servers and I noticed that the ".EventID" property returns an incorrect integerMy Code Snippet: foreach (EventLogEntry entry in log.Entries.Cast<EventLogEntry>().Reverse()) { string EventID = entry.EventID; //this value is sometimes incorrect }The eventID my application is pulling is 263169 but the actual eventID is 1025Any idea as to why this .EventID property is correct only 95% of the time? 解决方案 As described here:Windows event viewer treat EventID as 16-bit integer (at least it's so as I test in WinXP), so you can cast it to UInt16 to display the same ID as in Event Viewer.foreach (EventLogEntry entry in log.Entries.Cast<EventLogEntry>().Reverse()){ var EventID = (UInt16)entry.InstanceId;} 这篇关于在某些记录中循环浏览事件日志和EventID似乎是错误的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-10 03:49