private void ProbeEvent(EventSchema eventSchema, EventSource source) { using (var listener = new ProbeEventListener(eventSchema, this)) { try { listener.EnableEvents(source, eventSchema.Level, eventSchema.Keywords); MethodInfo method; if (this.TryInvokeMethod(eventSchema, source, listener, out method)) { if (listener.EventData == null) { throw new EventSourceAnalyzerException(string.Format(CultureInfo.CurrentCulture, Resources.EventSourceAnalyzerMissingWriteEventCallError, method.Name)); } if (listener.Error != null) { throw listener.Error; } } } finally { listener.DisableEvents(source); } } }
public void Enqueue() { using (ProbeEventListener listener = new ProbeEventListener()) { // arrange listener.EnableEvents(ProbeEventListenerEventSource.Log, EventLevel.Verbose); listener.EventSourceCreated += (sender, eventArgs) => _output.WriteLine($"Created event source: {eventArgs.EventSource.Name}"); // act ProbeEventListenerEventSource.Log.Foo("1"); ProbeEventListenerEventSource.Log.Bar("2"); ProbeEventListenerEventSource.Log.Foo("3"); // assert Assert.Collection(listener.OrderedEvents, e => { Assert.Equal("Foo", e.EventName); Assert.Equal("1", e.Payload.Single()); }, e => { Assert.Equal("Bar", e.EventName); Assert.Equal("2", e.Payload.Single()); }, e => { Assert.Equal("Foo", e.EventName); Assert.Equal("3", e.Payload.Single()); }); } }
private void CheckEnableEvents(EventSource eventSource) { using (var listener = new ProbeEventListener()) { //// EnableEvents will do a general validation pass listener.EnableEvents(eventSource, EventLevel.LogAlways); //// Restore source listener.DisableEvents(eventSource); } }
private void ProbeEvent(EventSchema eventSchema, EventSource source) { using (var listener = new ProbeEventListener(eventSchema, this)) { try { listener.EnableEvents(source, eventSchema.Level, eventSchema.Keywords); MethodInfo method; if (this.TryInvokeMethod(eventSchema, source, listener, out method)) { if (listener.EventData == null) { throw new EventSourceAnalyzerException(string.Format(CultureInfo.CurrentCulture, Properties.Resources.EventSourceAnalyzerMissingWriteEventCallError, method.Name)); } if (listener.Error != null) { throw listener.Error; } } } finally { listener.DisableEvents(source); } } }