public void WhenEnumsInPayload()
        {
            var validConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["valid"].ConnectionString;
            DatabaseHelper.CleanLoggingDB(validConnectionString);
            var logger = MockEventSourceOutProcEnum.Logger;
            EventTextFormatter formatter = new EventTextFormatter();

            System.Data.DataTable eventsDataTable = null;
            var subject = new EventEntrySubject();
            subject.LogToSqlDatabase("testInstance", validConnectionString, "Traces", bufferingCount: 1);
            EventSourceSettings settings = new EventSourceSettings("MockEventSourceOutProcEnum", null, EventLevel.LogAlways);
            SinkSettings sinkSettings = new SinkSettings("sqlDBsink", subject, new List<EventSourceSettings>() { { settings } });
            List<SinkSettings> sinks = new List<SinkSettings>() { { sinkSettings } };
            TraceEventServiceConfiguration svcConfiguration = new TraceEventServiceConfiguration(sinks);
            TestScenario.WithConfiguration(
                svcConfiguration,
                () =>
                {
                    logger.SendEnumsEvent16(MockEventSourceOutProcEnum.MyColor.Blue, MockEventSourceOutProcEnum.MyFlags.Flag3);

                    eventsDataTable = DatabaseHelper.PollUntilEventsAreWritten(validConnectionString, 1);
                });

            Assert.AreEqual(1, eventsDataTable.Rows.Count);
            StringAssert.Contains(eventsDataTable.Rows[0]["payload"].ToString(), @"""a"": 1");
            StringAssert.Contains(eventsDataTable.Rows[0]["payload"].ToString(), @"""b"": 4");
        }
        public void WhenUsingSinkProgrammatically()
        {
            var validConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["valid"].ConnectionString;
            DatabaseHelper.CleanLoggingDB(validConnectionString);
            var logger = MockEventSourceOutProc.Logger;
            EventTextFormatter formatter = new EventTextFormatter();
            EventSourceSettings settings = new EventSourceSettings("MockEventSourceOutProc", null, EventLevel.LogAlways);
            var subject = new EventEntrySubject();
            subject.LogToSqlDatabase("testInstance", validConnectionString, "Traces", TimeSpan.FromSeconds(1), 1);

            System.Data.DataTable eventsDataTable = null;
            SinkSettings sinkSettings = new SinkSettings("sqlDBsink", subject, new List<EventSourceSettings>() { { settings } });
            List<SinkSettings> sinks = new List<SinkSettings>() { { sinkSettings } };
            TraceEventServiceConfiguration svcConfiguration = new TraceEventServiceConfiguration(sinks);
            TestScenario.WithConfiguration(
                svcConfiguration,
                () =>
                {
                    for (int n = 0; n < 10; n++)
                    {
                        logger.LogSomeMessage("some message" + n.ToString());
                    }

                    eventsDataTable = DatabaseHelper.PollUntilEventsAreWritten(validConnectionString, 10);
                });

            Assert.AreEqual(10, eventsDataTable.Rows.Count);
            StringAssert.Contains(eventsDataTable.Rows[0]["payload"].ToString(), "some message");
        }
Пример #3
0
        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 EventSourceSettings(EventSource.GetName(typeof(MyCompanyEventSource)));
            this.eventSources   = new List <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();
        }
        public void WhenConcurrentEventsRaised()
        {
            var logger = MockEventSourceOutProc.Logger;
            EventTextFormatter formatter = new EventTextFormatter();
            EventSourceSettings settings = new EventSourceSettings("MockEventSourceOutProc", null, EventLevel.LogAlways);
            InMemorySink sink = new InMemorySink(formatter);

            SinkSettings sinkSettings = new SinkSettings("memorySink", sink, new List<EventSourceSettings>() { { settings } });
            List<SinkSettings> sinks = new List<SinkSettings>() { { sinkSettings } };
            TraceEventServiceConfiguration svcConfiguration = new TraceEventServiceConfiguration(sinks);
            TestScenario.WithConfiguration(
                svcConfiguration,
                () =>
                {
                    sink.WaitSignalCondition = () => sink.EventWrittenCount == 100;
                    for (int n = 0; n < 100; n++)
                    {
                        logger.LogSomeMessage("some message" + n.ToString());
                    }

                    sink.WaitOnAsyncEvents.WaitOne(TimeSpan.FromSeconds(10));
                });

            StringAssert.Contains(sink.ToString(), "some message99");
        }
        public void WhenConfiguringProgrammatically()
        {
            this.tableName = "testoutofprocazuretables";
            var connectionString = System.Configuration.ConfigurationManager.AppSettings["StorageConnectionString"];
            AzureTableHelper.DeleteTable(connectionString, this.tableName);
            var logger = MockEventSourceOutProc.Logger;
            EventTextFormatter formatter = new EventTextFormatter();

            IEnumerable<WindowsAzureTableEventEntry> events = null;
            EventSourceSettings settings = new EventSourceSettings("MockEventSourceOutProc", null, EventLevel.LogAlways);
            var subject = new EventEntrySubject();
            subject.LogToWindowsAzureTable("AzureInstance", connectionString, tableName, TimeSpan.FromSeconds(1));
            SinkSettings sinkSettings = new SinkSettings("azureSink", subject, new List<EventSourceSettings>() { { settings } });
            List<SinkSettings> sinks = new List<SinkSettings>() { { sinkSettings } };
            TraceEventServiceConfiguration svcConfiguration = new TraceEventServiceConfiguration(sinks);
            TestScenario.WithConfiguration(
                svcConfiguration,
                () =>
                {
                    for (int i = 0; i < 10; i++)
                    {
                        logger.Critical("Critical message");
                    }

                    events = AzureTableHelper.PollForEvents(connectionString, this.tableName, 10);
                });

            Assert.AreEqual<int>(10, events.Count());
            Assert.AreEqual<int>(2, events.First().EventId);
        }
        public void WhenUsingRollingSinkProgrammatic()
        {
            var logger = MockEventSourceOutProc.Logger;
            EventTextFormatter formatter = new EventTextFormatter(EventTextFormatter.DashSeparator);
            var fileName = "newRollingFlatfileSerial.log";
            File.Delete(fileName);
            EventSourceSettings settings = new EventSourceSettings("MockEventSourceOutProc", null, EventLevel.LogAlways);
            var subject = new EventEntrySubject();
            subject.LogToRollingFlatFile(fileName, 100, "d", RollFileExistsBehavior.Overwrite, RollInterval.Day, formatter);

            SinkSettings sinkSettings = new SinkSettings("rollingFlatFileSink", subject, new List<EventSourceSettings>() { { settings } });
            List<SinkSettings> sinks = new List<SinkSettings>() { { sinkSettings } };
            TraceEventServiceConfiguration svcConfiguration = new TraceEventServiceConfiguration(sinks);
            IEnumerable<string> entries = null;
            TestScenario.WithConfiguration(
                svcConfiguration,
                () =>
                {
                    for (int n = 0; n < 200; n++)
                    {
                        logger.LogSomeMessage("some message" + n.ToString());
                    }

                    entries = FlatFileHelper.PollUntilTextEventsAreWritten(fileName, 200, EventTextFormatter.DashSeparator);
                });

            Assert.AreEqual(200, entries.Count());
            StringAssert.Contains(entries.First(), "some message0");
            StringAssert.Contains(entries.Last(), "some message199");
        }
        public void when_creating_instance_with_id_only()
        {
            var sut = new 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);
        }
Пример #8
0
        public void when_creating_instance_with_id_only()
        {
            var sut = new 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);
        }
        public void WhenUsingTwoCollectorsForSameEventSourceWithDifferentSinkTypes()
        {
            var validConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["valid"].ConnectionString;
            DatabaseHelper.CleanLoggingDB(validConnectionString);
            string fileName = "TwoCollectorsSameEventSourceDifferentSinkTypes.log";
            File.Delete(fileName);
            string header = "===========";
            var logger = MockEventSourceOutProc.Logger;
            EventTextFormatter formatter = new EventTextFormatter(header);
            EventSourceSettings settings = new EventSourceSettings("MockEventSourceOutProc", null, EventLevel.LogAlways);

            var subject = new EventEntrySubject();
            subject.LogToSqlDatabase("testInstance", validConnectionString, "Traces", TimeSpan.FromSeconds(1), 1);
            SinkSettings sinkSettings = new SinkSettings("dbSink", subject, new List<EventSourceSettings>() { { settings } });

            var subject2 = new EventEntrySubject();
            subject2.LogToFlatFile(fileName, formatter);
            SinkSettings sinkSettings2 = new SinkSettings("ffSink", subject2, new List<EventSourceSettings>() { { settings } });

            System.Data.DataTable eventsDataTable = null;
            List<SinkSettings> sinks = new List<SinkSettings>() { sinkSettings, sinkSettings2 };
            TraceEventServiceConfiguration svcConfiguration = new TraceEventServiceConfiguration(sinks);
            IEnumerable<string> entries = null;
            using (TraceEventService collector = new TraceEventService(svcConfiguration))
            using (TraceEventService collector2 = new TraceEventService(svcConfiguration))
            {
                collector.Start();
                collector2.Start();
                try
                {
                    for (int n = 0; n < 10; n++)
                    {
                        logger.LogSomeMessage("some message" + n.ToString());
                    }

                    eventsDataTable = DatabaseHelper.PollUntilEventsAreWritten(validConnectionString, 10);

                    entries = FlatFileHelper.PollUntilTextEventsAreWritten(fileName, 10, header);
                }
                finally
                {
                    collector.Stop();
                    collector2.Stop();
                }
            }

            Assert.AreEqual(10, eventsDataTable.Rows.Count);
            StringAssert.Contains(eventsDataTable.Rows[0]["payload"].ToString(), "some message");

            Assert.AreEqual(10, entries.Count());
            StringAssert.Contains(entries.First(), "some message0");
            StringAssert.Contains(entries.Last(), "some message9");
        }
Пример #10
0
            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 EventSourceSettings(EventSource.GetName(typeof(MyCompanyEventSource)), level: EventLevel.Warning);
                var localEventSources   = new List <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 EventSourceSettings(currentEventSource.Name, level: currentEventSource.Level, matchAnyKeyword: EventKeywords.AuditSuccess);

                this.Sut.UpdateSession(new List <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);
            }
Пример #12
0
            protected override void Given()
            {
                base.Given();
                inMemoryListener.WaitSignalCondition = () => inMemoryListener.EventWrittenCount == 2;
                var sink = new Lazy <IObserver <EventEntry> >(() => inMemoryListener);
                var localSourceSettings = new 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();
            }
Пример #13
0
            protected override void Given()
            {
                base.Given();
                var sink = new Lazy <IObserver <EventEntry> >(() => inMemoryListener);

                sourceSettings = new EventSourceSettings(EventSource.GetName(typeof(MyCompanyEventSource)), level: EventLevel.Warning, matchAnyKeyword: MyCompanyEventSource.Keywords.Diagnostic);
                eventSources   = new List <EventSourceSettings> {
                    sourceSettings
                };
                sinkSettings = new List <SinkSettings> {
                    new SinkSettings("test", sink, eventSources)
                };
                configuration = new TraceEventServiceConfiguration(sinkSettings);
                this.sut      = new TraceEventService(configuration);
                this.sut.Start();
            }
        public void WhenUsingTwoCollectorsForSameEventSource()
        {
            var validConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["valid"].ConnectionString;
            DatabaseHelper.CleanLoggingDB(validConnectionString);
            var logger = MockEventSourceOutProc.Logger;
            EventTextFormatter formatter = new EventTextFormatter();
            EventSourceSettings settings = new EventSourceSettings("MockEventSourceOutProc", null, EventLevel.LogAlways);

            var subject = new EventEntrySubject();
            subject.LogToSqlDatabase("testInstance", validConnectionString, "Traces", TimeSpan.FromSeconds(1), 1);
            SinkSettings sinkSettings = new SinkSettings("dbSink", subject, new List<EventSourceSettings>() { { settings } });

            var subject2 = new EventEntrySubject();
            subject2.LogToSqlDatabase("testInstance", validConnectionString, "Traces", TimeSpan.FromSeconds(1), 1);
            SinkSettings sinkSettings2 = new SinkSettings("dbSink2", subject2, new List<EventSourceSettings>() { { settings } });

            System.Data.DataTable eventsDataTable = null;
            List<SinkSettings> sinks = new List<SinkSettings>() { sinkSettings, sinkSettings2 };
            TraceEventServiceConfiguration svcConfiguration = new TraceEventServiceConfiguration(sinks);
            using (TraceEventService collector = new TraceEventService(svcConfiguration))
            using (TraceEventService collector2 = new TraceEventService(svcConfiguration))
            {
                collector.Start();
                collector2.Start();
                try
                {
                    for (int n = 0; n < 10; n++)
                    {
                        logger.LogSomeMessage("some message" + n.ToString());
                    }

                    eventsDataTable = DatabaseHelper.PollUntilEventsAreWritten(validConnectionString, 20);
                }
                finally
                {
                    collector.Stop();
                    collector2.Stop();
                }
            }

            Assert.AreEqual(20, eventsDataTable.Rows.Count);
            StringAssert.Contains(eventsDataTable.Rows[0]["payload"].ToString(), "some message");
        }
            public void then_session_is_updated_with_new_eventSources_with_filters_and_arguments()
            {
                var currentEventSource = this.sinkSettings.EventSources.First();
                var newEventSource     =
                    new 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 <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);
            }
Пример #16
0
            protected override void Given()
            {
                RemoveAnyExistingSession(SessionName2);
                base.Given();

                inMemoryListener2 = new InMemoryEventListener(formatter);
                var sink = new Lazy <IObserver <EventEntry> >(() => inMemoryListener2);
                var localSourceSettings = new EventSourceSettings(EventSource.GetName(typeof(MyCompanyEventSource)), level: EventLevel.Informational, matchAnyKeyword: MyCompanyEventSource.Keywords.Page);
                var localEventSources   = new List <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);
            }
Пример #17
0
            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 EventSourceSettings(EventSource.GetName(typeof(MyCompanyEventSource)));
                eventSources   = new List <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();
            }
Пример #18
0
        protected override void Given()
        {
            this.formatter = new MockFormatter();
            this.inMemoryListener = new InMemoryEventListener(this.formatter);
            var sink = new Lazy<IObserver<EventEntry>>(() => this.inMemoryListener);
            this.sourceSettings = this.sourceSettings ?? new EventSourceSettings(EventSource.GetName(typeof(MyCompanyEventSource)));
            this.eventSources = new List<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();
        }
 protected override void Given()
 {
     base.Given();
     inMemoryListener.WaitSignalCondition = () => inMemoryListener.EventWrittenCount == 2;
     var sink = new Lazy<IObserver<EventEntry>>(() => inMemoryListener);
     var localSourceSettings = new 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();
                inMemoryListener = new InMemoryEventListener(new MockFormatter { BeforeWriteEventAction = f => { throw new Exception("unhandled_exception_test"); } });
                var sink = new Lazy<IObserver<EventEntry>>(() => inMemoryListener);
                sourceSettings = new EventSourceSettings(EventSource.GetName(typeof(MyCompanyEventSource)));
                eventSources = new List<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();
            }
 protected override void Given()
 {
     base.Given();
     var sink = new Lazy<IObserver<EventEntry>>(() => inMemoryListener);
     sourceSettings = new EventSourceSettings(EventSource.GetName(typeof(MyCompanyEventSource)), level: EventLevel.Warning);
     eventSources = new List<EventSourceSettings> { sourceSettings };
     sinkSettings = new List<SinkSettings> { new SinkSettings("test", sink, eventSources) };
     configuration = new TraceEventServiceConfiguration(sinkSettings);
     this.sut = new TraceEventService(configuration);
     this.sut.Start();
 }
Пример #22
0
        public void WhenCustomFormatterThrowsAnExceptionAndUsedProgramatically()
        {
            string fileName = "FlatFileOutProcCustomFormatterHandleException.log";
            File.Delete(fileName);
            var logger = MockEventSourceOutProc.Logger;
            MockFormatter formatter = new MockFormatter(true); //this formatter throws

            EventSourceSettings settings = new EventSourceSettings("MockEventSourceOutProc", null, EventLevel.Informational);
            var subject = new EventEntrySubject();
            subject.LogToFlatFile(fileName, formatter);
            SinkSettings sinkSettings = new SinkSettings("flatFileSink", subject, new List<EventSourceSettings>() { { settings } });
            List<SinkSettings> sinks = new List<SinkSettings>() { { sinkSettings } };
            TraceEventServiceConfiguration svcConfiguration = new TraceEventServiceConfiguration(sinks);
            TestScenario.WithConfiguration(
                svcConfiguration,
                () =>
                {
                    using (var collectErrorsListener = new InMemoryEventListener())
                    {
                        try
                        {
                            collectErrorsListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.LogAlways, Keywords.All);

                            logger.LogSomeMessage("some message using formatter that throws");
                            collectErrorsListener.WaitEvents.Wait(5000);

                            StringAssert.Contains(collectErrorsListener.ToString(), "Payload : [message : System.InvalidOperationException: Operation is not valid due to the current state of the object.");
                        }
                        finally
                        {
                            collectErrorsListener.DisableEvents(SemanticLoggingEventSource.Log);
                        }
                    }
                });
        }
            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 EventSourceSettings(EventSource.GetName(typeof(MyCompanyEventSource)), level: EventLevel.Warning);
                var localEventSources = new List<EventSourceSettings> { localSourceSettings };
                this.configuration.SinkSettings.Add(new SinkSettings("test2", sink, localEventSources));
            }
Пример #24
0
        public void WhenUsingCustomFormatterProgramatically()
        {
            string fileName = "FlatFileCustomFormatterProgrammatic.log";
            File.Delete(fileName);
            var logger = MockEventSourceOutProc.Logger;
            CustomFormatterWithWait formatter = new CustomFormatterWithWait();
            formatter.Detailed = EventLevel.LogAlways;
            formatter.Header = "---------------";
            formatter.DateTimeFormat = "d";

            IEnumerable<string> entries = null;
            EventSourceSettings settings = new EventSourceSettings("MockEventSourceOutProc", null, EventLevel.Critical);
            var subject = new EventEntrySubject();
            subject.LogToFlatFile(fileName, formatter);
            SinkSettings sinkSettings = new SinkSettings("flatFileSink", subject, new List<EventSourceSettings>() { { settings } });
            List<SinkSettings> sinks = new List<SinkSettings>() { { sinkSettings } };
            TraceEventServiceConfiguration svcConfiguration = new TraceEventServiceConfiguration(sinks);
            TestScenario.WithConfiguration(
                svcConfiguration,
                () =>
                {
                    logger.Critical("some message using formatter");

                    entries = FlatFileHelper.PollUntilTextEventsAreWritten(fileName, 1, "---------------");
                });

            StringAssert.Contains(entries.First(), "Mock SourceId");
            StringAssert.Contains(entries.First(), "Mock EventId");
            StringAssert.Contains(entries.First(), "Payload : [message : some message using formatter]");
        }
        public void WhenInfoAndMoreVerboseLevelsAreFiltered()
        {
            var logger = MockEventSourceOutProc.Logger;
            EventTextFormatter formatter = new EventTextFormatter(EventTextFormatter.DashSeparator);
            var fileName = "FlatFileAllFiltered.log";
            File.Delete(fileName);

            EventSourceSettings settings = new EventSourceSettings("MockEventSourceOutProc", null, EventLevel.Error);
            var subject = new EventEntrySubject();
            subject.LogToFlatFile(fileName, formatter);

            SinkSettings sinkSettings = new SinkSettings("flatFileSink", subject, new List<EventSourceSettings>() { { settings } });
            List<SinkSettings> sinks = new List<SinkSettings>() { { sinkSettings } };
            TraceEventServiceConfiguration svcConfiguration = new TraceEventServiceConfiguration(sinks);
            IEnumerable<string> entries = null;
            TestScenario.WithConfiguration(
                svcConfiguration,
                () =>
                {
                    for (int n = 0; n < 200; n++)
                    {
                        logger.LogSomeMessage("some message " + n.ToString());
                        logger.Critical("some error " + n.ToString());
                    }

                    entries = FlatFileHelper.PollUntilTextEventsAreWritten(fileName, 200, EventTextFormatter.DashSeparator);
                });

            Assert.AreEqual(200, entries.Count());
            StringAssert.Contains(entries.First(), "some error 0");
            StringAssert.Contains(entries.Last(), "some error 199");
        }
            public void then_session_is_updated_with_new_eventSources()
            {
                var currentEventSource = this.sinkSettings.EventSources.First();
                var newEventSource = new EventSourceSettings(currentEventSource.Name, level: currentEventSource.Level, matchAnyKeyword: EventKeywords.AuditSuccess);

                this.Sut.UpdateSession(new List<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()
            {
                RemoveAnyExistingSession(SessionName2);
                base.Given();

                inMemoryListener2 = new InMemoryEventListener(formatter);
                var sink = new Lazy<IObserver<EventEntry>>(() => inMemoryListener2);
                var localSourceSettings = new EventSourceSettings(EventSource.GetName(typeof(MyCompanyEventSource)), level: EventLevel.Informational, matchAnyKeyword: MyCompanyEventSource.Keywords.Page);
                var localEventSources = new List<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 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<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);
            }
        public void WhenSinkNameIsDuplicated1()
        {
            var validConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["valid"].ConnectionString;
            DatabaseHelper.CleanLoggingDB(validConnectionString);
            var logger = MockEventSourceOutProc.Logger;

            EventSourceSettings settings = new EventSourceSettings("MockEventSourceOutProc", null, EventLevel.LogAlways);
            var subject = new EventEntrySubject();
            subject.LogToSqlDatabase("testInstance", validConnectionString, "Traces", TimeSpan.FromSeconds(10), 200);
            SinkSettings sinkSettings = new SinkSettings("dbSink", subject, new List<EventSourceSettings>() { { settings } });
            var subject2 = new EventEntrySubject();
            subject2.LogToSqlDatabase("testInstance", validConnectionString, "Traces", TimeSpan.FromSeconds(10), 200);
            SinkSettings sinkSettings2 = new SinkSettings("dbSink", subject2, new List<EventSourceSettings>() { { settings } });
            List<SinkSettings> sinks = new List<SinkSettings>() { sinkSettings, sinkSettings2 };
            var exc = ExceptionAssertHelper.
                Throws<Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Etw.Configuration.ConfigurationException>(
                            () => new TraceEventServiceConfiguration(sinks));

            StringAssert.Contains(exc.ToString(), "Duplicate sinks");
        }
        public void WhenThreadId()
        {
            var validConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["valid"].ConnectionString;
            DatabaseHelper.CleanLoggingDB(validConnectionString);
            var logger = MockEventSourceOutProcEnum.Logger;
            EventTextFormatter formatter = new EventTextFormatter();

            System.Data.DataTable eventsDataTable = null;
            var subject = new EventEntrySubject();
            subject.LogToSqlDatabase("testInstance", validConnectionString, "Traces", bufferingCount: 1);
            EventSourceSettings settings = new EventSourceSettings("MockEventSourceOutProcEnum", null, EventLevel.LogAlways);
            SinkSettings sinkSettings = new SinkSettings("sqlDBsink", subject, new List<EventSourceSettings>() { { settings } });
            List<SinkSettings> sinks = new List<SinkSettings>() { { sinkSettings } };
            TraceEventServiceConfiguration svcConfiguration = new TraceEventServiceConfiguration(sinks);
            TestScenario.WithConfiguration(
                svcConfiguration,
                () =>
                {
                    logger.SaveExpenseStarted(Guid.NewGuid());

                    eventsDataTable = DatabaseHelper.PollUntilEventsAreWritten(validConnectionString, 1);
                });

            Assert.AreEqual(1, eventsDataTable.Rows.Count);
            Assert.AreEqual(ThreadHelper.GetCurrentUnManagedThreadId(), Convert.ToInt32(eventsDataTable.Rows[0]["ThreadId"]));
        }
 internal void CopyValuesFrom(EventSourceSettings settings)
 {
     this.Level = settings.Level;
     this.MatchAnyKeyword = settings.MatchAnyKeyword;
     this.Arguments = settings.Arguments;
     this.ProcessNamesToFilter = settings.ProcessNamesToFilter;
 }
Пример #32
0
        public void WhenUsingCustomSinkProgrammatically()
        {
            string fileName = "ProvidedCustomSink.log";
            File.Delete(fileName);
            var logger = MockEventSourceOutProc.Logger;
            var formatter = new EventTextFormatter();

            IEnumerable<string> entries = null;
            var subject = new EventEntrySubject();
            subject.LogToMockFlatFile(fileName, "==-==");
            EventSourceSettings settings = new EventSourceSettings("MockEventSourceOutProc", null, EventLevel.LogAlways);
            SinkSettings sinkSettings = new SinkSettings("MockFlatFileSink", subject, new List<EventSourceSettings>() { { settings } });
            List<SinkSettings> sinks = new List<SinkSettings>() { { sinkSettings } };
            TraceEventServiceConfiguration svcConfiguration = new TraceEventServiceConfiguration(sinks);
            TestScenario.WithConfiguration(
                svcConfiguration,
                () =>
                {
                    logger.LogSomeMessage("some message");
                    logger.LogSomeMessage("some message2");
                    logger.LogSomeMessage("some message3");

                    entries = FlatFileHelper.PollUntilTextEventsAreWritten(fileName, 3, "==-==");
                });

            Assert.AreEqual<int>(3, entries.Count());
            Assert.IsNotNull(entries.SingleOrDefault(e => e.Contains("Payload : [message : some message]")));
            Assert.IsNotNull(entries.SingleOrDefault(e => e.Contains("Payload : [message : some message2]")));
            Assert.IsNotNull(entries.SingleOrDefault(e => e.Contains("Payload : [message : some message3]")));
        }