Exemplo n.º 1
0
        public void EventsAreFilteredByVerbosity()
        {
            using (JsonEtwTracer tracer = new JsonEtwTracer("Microsoft-GVFS-Test", "EventsAreFilteredByVerbosity1"))
                using (MockListener listener = new MockListener(EventLevel.Informational, Keywords.Any))
                {
                    tracer.AddInProcEventListener(listener);

                    tracer.RelatedEvent(EventLevel.Informational, "ShouldReceive", metadata: null);
                    listener.EventNamesRead.ShouldContain(name => name.Equals("ShouldReceive"));

                    tracer.RelatedEvent(EventLevel.Verbose, "ShouldNotReceive", metadata: null);
                    listener.EventNamesRead.ShouldNotContain(name => name.Equals("ShouldNotReceive"));
                }

            using (JsonEtwTracer tracer = new JsonEtwTracer("Microsoft-GVFS-Test", "EventsAreFilteredByVerbosity2"))
                using (MockListener listener = new MockListener(EventLevel.Verbose, Keywords.Any))
                {
                    tracer.AddInProcEventListener(listener);

                    tracer.RelatedEvent(EventLevel.Informational, "ShouldReceive", metadata: null);
                    listener.EventNamesRead.ShouldContain(name => name.Equals("ShouldReceive"));

                    tracer.RelatedEvent(EventLevel.Verbose, "ShouldAlsoReceive", metadata: null);
                    listener.EventNamesRead.ShouldContain(name => name.Equals("ShouldAlsoReceive"));
                }
        }
Exemplo n.º 2
0
        public void EventsAreFilteredByKeyword()
        {
            // Network filters all but network out
            using (JsonEtwTracer tracer = new JsonEtwTracer("Microsoft-GVFS-Test", "EventsAreFilteredByKeyword1"))
                using (MockListener listener = new MockListener(EventLevel.Verbose, Keywords.Network))
                {
                    tracer.AddInProcEventListener(listener);

                    tracer.RelatedEvent(EventLevel.Informational, "ShouldReceive", metadata: null, keyword: Keywords.Network);
                    listener.EventNamesRead.ShouldContain(name => name.Equals("ShouldReceive"));

                    tracer.RelatedEvent(EventLevel.Verbose, "ShouldNotReceive", metadata: null);
                    listener.EventNamesRead.ShouldNotContain(name => name.Equals("ShouldNotReceive"));
                }

            // Any filters nothing out
            using (JsonEtwTracer tracer = new JsonEtwTracer("Microsoft-GVFS-Test", "EventsAreFilteredByKeyword2"))
                using (MockListener listener = new MockListener(EventLevel.Verbose, Keywords.Any))
                {
                    tracer.AddInProcEventListener(listener);

                    tracer.RelatedEvent(EventLevel.Informational, "ShouldReceive", metadata: null, keyword: Keywords.Network);
                    listener.EventNamesRead.ShouldContain(name => name.Equals("ShouldReceive"));

                    tracer.RelatedEvent(EventLevel.Verbose, "ShouldAlsoReceive", metadata: null);
                    listener.EventNamesRead.ShouldContain(name => name.Equals("ShouldAlsoReceive"));
                }

            // None filters everything out (including events marked as none)
            using (JsonEtwTracer tracer = new JsonEtwTracer("Microsoft-GVFS-Test", "EventsAreFilteredByKeyword3"))
                using (MockListener listener = new MockListener(EventLevel.Verbose, Keywords.None))
                {
                    tracer.AddInProcEventListener(listener);

                    tracer.RelatedEvent(EventLevel.Informational, "ShouldNotReceive", metadata: null, keyword: Keywords.Network);
                    listener.EventNamesRead.ShouldBeEmpty();

                    tracer.RelatedEvent(EventLevel.Verbose, "ShouldAlsoNotReceive", metadata: null);
                    listener.EventNamesRead.ShouldBeEmpty();
                }
        }