在某些记录中循环浏览事件日志和EventID似乎是错误的 [英] Looping through the event log and the EventID appears to be wrong on some records

查看:57
本文介绍了在某些记录中循环浏览事件日志和EventID似乎是错误的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遍历多个远程服务器的事件日志,并且发现".EventID"属性返回错误的整数

我的代码段:

  foreach(log.Entries.Cast< EventLogEntry>().Reverse()中的EventLogEntry条目){字符串EventID = entry.EventID;//此值有时不正确} 

我的应用程序提取的eventID为263169,但实际的eventID为1025

关于为什么这个.EventID属性仅在95%的时间内正确的任何想法吗?

解决方案

My 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 1025

Any 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似乎是错误的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆