EventID?现在是InstanceID [英] EventID ?? is now InstanceID

查看:187
本文介绍了EventID?现在是InstanceID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,

在VB 2005上,Microsoft拥有将EventID更改为InstanceID的绝妙想法.我正在尝试在应用程序中检索eventid,但是在某些情况下,它附带的数字非常长.如何检索您可以在事件查看器中看到的EventID而不是InstanceID?有什么方法可以将InstanceID转换为EventID?

On VB 2005 microsoft had the wonderfull idea of change the Eventid for InstanceID.  I'm trying of retrieve the eventid in my application but it come with a very long number in some cases.  How can I retrieve the EventID that you can see in the Event Viewer instead of the InstanceID?  Is there a way I can convert the InstanceID to EventID?

例如:

私有 Sub btnSee_Click( ByVal 发送者 System.Object, ByVal e System.EventArgs) 句柄 btnFind.Click

Private Sub btnSee_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click

'创建一个EventLog实例并分配其源.

' Create an EventLog instance and assign its source.

'将myLog更改为新的EventLog("myNewLog",.","MySource")

'Dim myLog As New EventLog("myNewLog", ".", "MySource")

暗淡 条目 EventLogEntry

Dim entry As EventLogEntry

对于 每个 条目 EventLog1.Entries

For Each entry In EventLog1.Entries

Console.WriteLine(entry.InstanceId) '在这里,我得到了一个长数字,而不是事件查看器中可以看到的通常的4或5位数字.

Console.WriteLine(entry.InstanceId) ' here I got a long number instead the usual 4 or 5 digit number you can see in the event viewer.

Console.WriteLine(entry.Source& vbCrLf)

Console.WriteLine(entry.Source & vbCrLf)

下一个

Next

结束 Sub

End Sub

在此先感谢您的帮助.

推荐答案

您好,

根据MSDN库,可以使用屏蔽从实例ID派生出事件ID:

According to the MSDN library, the eventid can be derived from the instanceid using masking:

InstanceId 属性唯一地标识已配置事件源的事件条目.事件日志条目的 InstanceId 代表事件源的消息资源文件中事件的完整32位资源标识符.

The InstanceId property uniquely identifies an event entry for a configured event source. The InstanceId for an event log entry represents the full 32-bit resource identifier for the event in the message resource file for the event source. The EventID property equals the InstanceId with the top two bits masked off. Two event log entries from the same source can have matching EventID values, but have different InstanceId values due to differences in the top two bits of the resource identifier.

因此,您需要执行以下操作:

So to do this, you'd need to do something like:

暗淡 条目 EventLogEntry

Dim entry As EventLogEntry

lEventID Int32

Dim lEventID As Int32

对于 每个 条目 EventLog1.Entries

For Each entry In EventLog1.Entries

Debug.WriteLine(entry.InstanceId)

Debug.WriteLine(entry.InstanceId)

'仅取实例ID的整数部分

'Take just the integer part of the instanceid

lEventID = CInt (entry.InstanceId /FONT> CLng (Int32.MaxValue))

lEventID = CInt(entry.InstanceId And CLng(Int32.MaxValue))

'擦除前两位

'Wipe out the top two bits

lEventID =(lEventID And & H3FFFFFFF)

lEventID = (lEventID And &H3FFFFFFF)

'写出事件ID

'write out the eventid

Debug.WriteLine(lEventID.ToString)

Debug.WriteLine(lEventID.ToString)

Debug.WriteLine(entry.Source& vbCrLf)

Debug.WriteLine(entry.Source & vbCrLf)

下一个

这应该给您带来的帮助:)

This should give you what you're after :)


这篇关于EventID?现在是InstanceID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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