我正在使用C++編寫COM程序。我想用清單的Windows事件跟蹤(ETW)記錄所有的COM-Interface調用(包括傳遞的參數)。 因爲我的程序中有數百種不同的接口方法,所以我希望在我的清單中有一個「通用」ETW事件,我可以傳遞接口名稱,方法名稱和參數。到目前爲止,這是我該事件的模板的樣子:如何讓結構數據正確顯示在基於清單的ETW提供程序中?
<templates>
<template tid="comInterfaceMethodCall" name="COM Interface Method Call">
<data name="COM Object" inType="win:UnicodeString" />
<data name="COM Interface" inType ="win:UnicodeString" />
<data name="Interface Method" inType="win:UnicodeString" />
<data name="Argument Count" inType="win:UInt16" />
<struct name="Arguments" count="Argument Count" >
<data name="Argument Name" inType="win:UnicodeString" />
<data name="Argument Type" inType="win:UnicodeString" />
<data name="Argument Value" inType="win:UnicodeString" />
</struct>
<UserData>
<EventData xmlns="ProviderNamespace" name="COM Interface Method Call">
<ComObject> %1 </ComObject>
<ComInterface> %2 </ComInterface>
<InterfaceMethod> %3 </InterfaceMethod>
<Arguments> %5 </Arguments>
</EventData>
</UserData>
</template>
</templates>
This是事件看起來像在事件查看器。 正如您所看到的,除了顯示爲十六進制二進制字符串的結構數據之外,所有內容都可以正確顯示。我檢查了二進制數據,它是正確的,所以顯然我正確地將數據傳遞給EvenWrite函數!正如清單中所述,我只想將其呈現爲字符串。
我已經嘗試過:擺脫結構,並直接向其成員提供:
<data name="COM Object" inType="win:UnicodeString" />
<data name="COM Interface" inType ="win:UnicodeString" />
<data name="Interface Method" inType="win:UnicodeString" />
<data name="Argument Count" inType="win:UInt16" />
<data name="Argument Name" inType="win:UnicodeString" count="Argument Count" />
<data name="Argument Type" inType="win:UnicodeString" count="Argument Count" />
<data name="Argument Value" inType="win:UnicodeString" count="Argument Count" />
這樣的作品,但它不是我想要的。對於一個有10個參數的方法,它會首先顯示10個名稱,然後顯示10個類型,最後顯示10個值。但我想擁有10個(姓名,類型,價值)三元組。
感謝您的幫助!
感謝您的回答!所以你說我的清單是正確的,但EventLog只是無法渲染結構數據?這是非常令人失望的,因爲我曾經預計MS會提供一個適當的內置消費者,它與清單所提供的內容更加兼容......假設我可以說服我的客戶使用不同的使用者工具,那麼有沒有辦法在清單中引用struct的字段?現在我只是使用%5來引用整個結構。類似%5.%1的內容會很有幫助。使用清單文件是可怕的.... – Yira
EventLog是一個大型生態系統。它提供了一個API,並且該API提供了一個簡單的數組系統來訪問事件中的數據。這需要對此API進行重大更改才能支持更復雜的數據結構。 EventLog不是打破API,而是選擇將你的結構扁平化爲一個單一的值,它提供的數據不會破壞剩下的EventLog框架。 –