我很困惑如何EventListener
为现有系统 ETW Provider 创建一个。该EnableEvents
方法期望在EventSource
实例中传递。我需要手动创建吗?有没有办法生成那个EventSource
类?
我可以找到提供者的详细信息:
logman query providers Microsoft-Windows-WinHttp
wevtutil get-publisher Microsoft-Windows-WinHttp
我什至可以instrumentationManifest
使用以下命令生成 xml:
.\PerfView.exe /nogui userCommand DumpRegisteredManifest Microsoft-Windows-WinHttp
open System.Diagnostics.Tracing
let printfn format = Printf.ksprintf System.Diagnostics.Debug.WriteLine format
[<EventSource(Name="Microsoft-Windows-NDIS-PacketCapture", Guid="2ed6006e-4729-4609-b423-3ee7bcd678ef")>]
type NdisPacketCaptureEventSource() =
inherit EventSource()
let Ethernet = LanguagePrimitives.EnumOfValue<int64, EventKeywords>(0x1L)
let WirelessWAN = LanguagePrimitives.EnumOfValue<int64, EventKeywords>(0x200L)
let Api = LanguagePrimitives.EnumOfValue<int64, EventKeywords>(0x1L)
let Send = LanguagePrimitives.EnumOfValue<int64, EventKeywords>(0x100000000L)
[<EventSource(Name="Microsoft-Windows-WinHttp", Guid="7d44233d-3055-4b9c-ba64-0d47ca40a232")>]
type WinHttpEventSource() =
inherit EventSource()
type MyEventListener() =
inherit EventListener()
override x.OnEventSourceCreated source =
printfn "OnEventSourceCreated %A" source
base.OnEventSourceCreated source
override x.OnEventWritten args =
printfn "OnEventWritten %A" args
base.OnEventWritten args
[<EntryPoint>]
let main argv =
use listener = new MyEventListener()
// use ndis = new NdisPacketCaptureEventSource()
// printfn "Name: %s, Guid: %A" ndis.Name ndis.Guid
// listener.EnableEvents(ndis, EventLevel.Verbose, EventKeywords.All)
// listener.EnableEvents(ndis, EventLevel.Verbose, Ethernet)
// listener.EnableEvents(ndis, EventLevel.Verbose, WirelessWAN)
use winHttp = new WinHttpEventSource()
// listener.EnableEvents(winHttp, EventLevel.Verbose, EventKeywords.All)
listener.EnableEvents(winHttp, EventLevel.Verbose, Send)
// for i in 0 .. 5 do
// System.Console.ReadKey() |> ignore
while true do
System.Threading.Thread.Sleep 100
0
我一直无法触发OnEventWritten
,我不知道为什么。有任何想法吗?
2015-12-02 更新
我能够EventSource
使用 SemanticLogging 获取事件记录。详情在这里。它正在使用Microsoft.Diagnostics.Tracing.TraceEvent。使用它似乎可能是解决方案。