private void OnEtwListenerRealtimeEvent(object sender, RealtimeEventArgs e) { if (Status != ServiceControllerStatus.Running) { return; } EventRealtimeListener listener = (EventRealtimeListener)sender; EtwRecord record = new EtwRecord(); record.ProcessId = e.ProcessId; record.ProcessName = GetProcessName(e.ProcessId); record.Text = e.Message; if (!_watch.IsRunning) { _watch.Start(); // small hack; we ensure the first record has 0 ticks record.Ticks = 0; } else { record.Ticks = _watch.ElapsedTicks; } long index = Buffer.AddAndGetIndex(record); record.Index = index; if (listener.ConsoleOutput) { Host.Log(this, listener.Description + "|#" + record.Index + "|" + record.Ticks + "|" + record.ProcessId + "|" + record.ProcessName + "|" + record.Text); } }
private void ProcessEtwTrace(object state) { EventRealtimeListener listener = (EventRealtimeListener)state; listener.ProcessTraces(); Host.Log(this, "Stopped listener for provider id: " + listener.ProviderGuid); }
public static void ProcessTraces(Guid providerGuid, string sessionName, EtwTraceLevel level, long keyword) { using (var listener = new EventRealtimeListener(providerGuid, sessionName, level, keyword)) { listener.ProcessTraces(); } }
public void Start() { Host.Log(this, "Circular Buffer Capacity: " + Buffer.Capacity + " records."); Host.Log(this, "Session Id: " + SessionId); Status = ServiceControllerStatus.StartPending; int count = 0; foreach (EtwProviderElement element in ServiceSection.Current.EtwListener.Providers.Cast <EtwProviderElement>().Where(e => e.Enabled)) { EventRealtimeListener listener = new EventRealtimeListener(element.Guid, element.Guid.ToString(), element.TraceLevel); if (!string.IsNullOrWhiteSpace(element.Description)) { listener.Description = element.Description; } listener.ConsoleOutput = element.ConsoleOutput || ServiceSection.Current.EtwListener.ConsoleOutput; Thread t = new Thread(ProcessEtwTrace); t.Start(listener); listener.RealtimeEvent += OnEtwListenerRealtimeEvent; Host.Log(this, "Added listener for provider id: " + element.Guid + ", Trace level: " + element.TraceLevel); _listeners.Add(listener); count++; } if (count == 0) { Host.Log(this, "No provider enabled. Aborting."); Status = ServiceControllerStatus.Stopped; return; } Status = ServiceControllerStatus.Running; }
public void Start() { Host.Log(this, "Circular Buffer Capacity: " + Buffer.Capacity + " records."); Host.Log(this, "Session Id: " + SessionId); Status = ServiceControllerStatus.StartPending; int count = 0; foreach (EtwProviderElement element in ServiceSection.Current.EtwListener.Providers.Cast<EtwProviderElement>().Where(e => e.Enabled)) { EventRealtimeListener listener = new EventRealtimeListener(element.Guid, element.Guid.ToString(), element.TraceLevel); if (!string.IsNullOrWhiteSpace(element.Description)) { listener.Description = element.Description; } listener.ConsoleOutput = element.ConsoleOutput || ServiceSection.Current.EtwListener.ConsoleOutput; Thread t = new Thread(ProcessEtwTrace); t.Start(listener); listener.RealtimeEvent += OnEtwListenerRealtimeEvent; Host.Log(this, "Added listener for provider id: " + element.Guid + ", Trace level: " + element.TraceLevel); _listeners.Add(listener); count++; } if (count == 0) { Host.Log(this, "No provider enabled. Aborting."); Status = ServiceControllerStatus.Stopped; return; } Status = ServiceControllerStatus.Running; }
public static void ProcessTraces(Guid providerGuid, string sessionName, EtwTraceLevel level, long keyword) { using (EventRealtimeListener listener = new EventRealtimeListener(providerGuid, sessionName, level, keyword)) { listener.ProcessTraces(); } }