private static void StopFunc() { if (etwWatcher != null) { etwWatcher.Dispose(); } if (etwSession != null) { etwSession.StopTrace(); } etwSession = null; etwWatcher = null; }
static void Main(string[] args) { string url = "http://localhost:8080"; using (WebApplication.Start <Startup>(url)) { Console.WriteLine("Server running on {0}", url); var hubConnection = new HubConnection("http://localhost:8080/"); var serverHub = hubConnection.CreateHubProxy("EventsHub"); hubConnection.Start().Wait(); var providerId = new Guid("13D5F7EF-9404-47ea-AF13-85484F09F2A7"); using (EventTraceWatcher watcher = new EventTraceWatcher("MySession", providerId)) { watcher.EventArrived += delegate(object sender, EventArrivedEventArgs e) { if (e.Error != null) { Console.Error.WriteLine(e.Error); Environment.Exit(-1); } // Dump properties (key/value) foreach (var p in e.Properties) { serverHub.Invoke("PushEvent", "\t" + p.Key + " -- " + p.Value).Wait(); } }; // Start listening watcher.Start(); Console.WriteLine("Listening...Press <Enter> to exit"); Console.ReadLine(); } Console.ReadLine(); } }
public static void Start(int ProcessID) { if (settings == null || settings.EtwEvents == null || settings.EtwEvents.Count == 0) { throw new Exception("No settings loaded."); } EtwSessionSetting etwSessionSettings = new EtwSessionSetting(); etwSessionSettings.RealTimeSession = true; etwSessionSettings.Name = etwSessionName; etwSessionSettings.BufferSize = 64; etwSession = new EtwSession(etwSessionSettings); etwSession.StartTrace(); List <Guid> guids = new List <Guid>(); List <Guid> providerGuids = new List <Guid>(); foreach (EtwEventInfo etwEventInfo in settings.EtwEvents) { if (!providerGuids.Contains(etwEventInfo.ProviderGuid)) { providerGuids.Add(etwEventInfo.ProviderGuid); etwSession.EnableProvider(etwEventInfo.ProviderGuid); } } etwWatcher = new EventTraceWatcher(etwSessionName); etwWatcher.EventArrived += new EventHandler <EventArrivedEventArgs>(etwWatcher_EventArrived); etwWatcher.Enabled = true; etwTotalEventCounter = 0; etwFilteredEventCounter = 0; processId = ProcessID; }