protected override void OnEventWritten(EventWrittenEventArgs eventData) { if (listenForCurrentContext && CurrentContextEvents.IsEntered()) { this.OnOnEventWritten(eventData); } }
public override void Dispose() { if (listenForCurrentContext) { CurrentContextEvents.Exit(); } base.Dispose(); }
public TestEventListener(bool waitForDelayedEvents = true, bool listenForCurrentContext = true) { this.events = new ConcurrentQueue <EventWrittenEventArgs>(); this.eventWritten = new AutoResetEvent(false); this.waitForDelayedEvents = waitForDelayedEvents; this.listenForCurrentContext = listenForCurrentContext; this.OnOnEventWritten = e => { this.events.Enqueue(e); this.eventWritten.Set(); }; if (this.listenForCurrentContext) { CurrentContextEvents.Enter(); } }