protected override void Given()
        {
            TraceEventManifestsCache.Clear();

            this.formatter        = new MockFormatter();
            this.inMemoryListener = new InMemoryEventListener(this.formatter);
            var sink = new Lazy <IObserver <EventEntry> >(() => this.inMemoryListener);

            this.sourceSettings = this.sourceSettings ?? new SemanticLogging.Etw.Configuration.EventSourceSettings(EventSource.GetName(typeof(MyCompanyEventSource)));
            this.eventSources   = new List <SemanticLogging.Etw.Configuration.EventSourceSettings> {
                this.sourceSettings
            };
            this.sinkSettings = new List <SinkSettings> {
                new SinkSettings("test", sink, this.eventSources)
            };
            this.configuration = new TraceEventServiceConfiguration(sinkSettings, this.serviceSettings);

            try
            {
                this.sut = new TraceEventService(configuration);
            }
            catch (UnauthorizedAccessException uae)
            {
                Assert.Inconclusive(uae.Message);
            }

            // Clean up any previous unclosed session to avoid collisions
            this.RemoveAnyExistingSession();
        }
Exemplo n.º 2
0
        public void when_creating_instance_with_id_only()
        {
            var sut = new SemanticLogging.Etw.Configuration.EventSourceSettings(eventSourceId: MyCompanyEventSource.Log.Guid);

            Assert.AreEqual(MyCompanyEventSource.Log.Guid.ToString(), sut.Name);
            Assert.AreEqual(MyCompanyEventSource.Log.Guid, sut.EventSourceId);
            Assert.AreEqual(EventLevel.LogAlways, sut.Level);
            Assert.AreEqual(Keywords.All, sut.MatchAnyKeyword);
        }
            protected override void When()
            {
                // We expect 3 events, 2 for listener1(Level=LogAlways) and 1 for listener2 (Level=Warning)
                inMemoryListener.WaitSignalCondition = () => inMemoryListener.EventWrittenCount == 3;

                var sink = new Lazy <IObserver <EventEntry> >(() => inMemoryListener);
                var localSourceSettings = new SemanticLogging.Etw.Configuration.EventSourceSettings(EventSource.GetName(typeof(MyCompanyEventSource)), level: EventLevel.Warning);
                var localEventSources   = new List <SemanticLogging.Etw.Configuration.EventSourceSettings> {
                    localSourceSettings
                };

                this.configuration.SinkSettings.Add(new SinkSettings("test2", sink, localEventSources));
            }
            public void then_session_is_updated_with_new_eventSources()
            {
                var currentEventSource = this.sinkSettings.EventSources.First();
                var newEventSource     = new SemanticLogging.Etw.Configuration.EventSourceSettings(currentEventSource.Name, level: currentEventSource.Level, matchAnyKeyword: EventKeywords.AuditSuccess);

                this.Sut.UpdateSession(new List <SemanticLogging.Etw.Configuration.EventSourceSettings> {
                    newEventSource
                });

                Assert.AreEqual(newEventSource.Level, currentEventSource.Level);
                Assert.AreEqual(newEventSource.MatchAnyKeyword, currentEventSource.MatchAnyKeyword);
                EnumerableAssert.AreEqual(newEventSource.Arguments, currentEventSource.Arguments);
                EnumerableAssert.AreEqual(newEventSource.ProcessNamesToFilter, currentEventSource.ProcessNamesToFilter);
            }
            protected override void Given()
            {
                base.Given();
                inMemoryListener.WaitSignalCondition = () => inMemoryListener.EventWrittenCount == 2;
                var sink = new Lazy <IObserver <EventEntry> >(() => inMemoryListener);
                var localSourceSettings = new SemanticLogging.Etw.Configuration.EventSourceSettings(EventSource.GetName(typeof(TestEventSource)));

                this.eventSources.Add(localSourceSettings);
                sinkSettings = new List <SinkSettings> {
                    new SinkSettings("test", sink, eventSources)
                };
                configuration = new TraceEventServiceConfiguration(sinkSettings);
                this.sut      = new TraceEventService(configuration);
                this.sut.Start();
            }
            protected override void Given()
            {
                base.Given();
                var sink = new Lazy <IObserver <EventEntry> >(() => inMemoryListener);

                sourceSettings = new SemanticLogging.Etw.Configuration.EventSourceSettings(EventSource.GetName(typeof(MyCompanyEventSource)), level: EventLevel.Warning, matchAnyKeyword: MyCompanyEventSource.Keywords.Diagnostic);
                eventSources   = new List <SemanticLogging.Etw.Configuration.EventSourceSettings> {
                    sourceSettings
                };
                sinkSettings = new List <SinkSettings> {
                    new SinkSettings("test", sink, eventSources)
                };
                configuration = new TraceEventServiceConfiguration(sinkSettings);
                this.sut      = new TraceEventService(configuration);
                this.sut.Start();
            }
            protected override void Given()
            {
                RemoveAnyExistingSession(SessionName2);
                base.Given();

                inMemoryListener2 = new InMemoryEventListener(formatter);
                var sink = new Lazy <IObserver <EventEntry> >(() => inMemoryListener2);
                var localSourceSettings = new SemanticLogging.Etw.Configuration.EventSourceSettings(EventSource.GetName(typeof(MyCompanyEventSource)), level: EventLevel.Informational, matchAnyKeyword: MyCompanyEventSource.Keywords.Page);
                var localEventSources   = new List <SemanticLogging.Etw.Configuration.EventSourceSettings> {
                    localSourceSettings
                };
                var localSinkSettings = new List <SinkSettings> {
                    new SinkSettings("test", sink, localEventSources)
                };
                var localConfiguration = new TraceEventServiceConfiguration(localSinkSettings, new TraceEventServiceSettings {
                    SessionNamePrefix = SessionName2
                });

                this.sut2 = new TraceEventService(localConfiguration);
            }
            public void then_session_is_updated_with_new_eventSources_with_filters_and_arguments()
            {
                var currentEventSource = this.sinkSettings.EventSources.First();
                var newEventSource     =
                    new SemanticLogging.Etw.Configuration.EventSourceSettings(
                        currentEventSource.Name,
                        level: currentEventSource.Level,
                        matchAnyKeyword: currentEventSource.MatchAnyKeyword,
                        arguments: new[] { new KeyValuePair <string, string>("key", "value") },
                        processNameFilters: new[] { "process" });

                this.Sut.UpdateSession(new List <SemanticLogging.Etw.Configuration.EventSourceSettings> {
                    newEventSource
                });

                Assert.AreEqual(newEventSource.Level, currentEventSource.Level);
                Assert.AreEqual(newEventSource.MatchAnyKeyword, currentEventSource.MatchAnyKeyword);
                EnumerableAssert.AreEqual(newEventSource.Arguments, currentEventSource.Arguments);
                EnumerableAssert.AreEqual(newEventSource.ProcessNamesToFilter, currentEventSource.ProcessNamesToFilter);
            }
            protected override void Given()
            {
                base.Given();
                inMemoryListener = new InMemoryEventListener(new MockFormatter {
                    BeforeWriteEventAction = f => { throw new Exception("unhandled_exception_test"); }
                });
                var sink = new Lazy <IObserver <EventEntry> >(() => inMemoryListener);

                sourceSettings = new SemanticLogging.Etw.Configuration.EventSourceSettings(EventSource.GetName(typeof(MyCompanyEventSource)));
                eventSources   = new List <SemanticLogging.Etw.Configuration.EventSourceSettings> {
                    sourceSettings
                };
                sinkSettings = new List <SinkSettings> {
                    new SinkSettings("test", sink, eventSources)
                };
                configuration = new TraceEventServiceConfiguration(sinkSettings);
                this.sut      = new TraceEventService(configuration);

                slabListener = new InMemoryEventListener();
                slabListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Error, SemanticLoggingEventSource.Keywords.TraceEvent);
                this.sut.Start();
            }