Example #1
0
 static LogManager()
 {
     _configuration = PulsusConfiguration.Default;
     _eventsFactory = new DefaultEventFactory();
     _eventDispatcher = new DefaultEventDispatcher(_configuration);
     _jsonSerializer = new JsonNetSerializer();
 }
        public void CanPushToTargets()
        {
            var target1Mock = new Mock<Target>();
            var target2Mock = new Mock<Target>();

            var configuration = new PulsusConfiguration();
            configuration.AddTarget("1", target1Mock.Object);
            configuration.AddTarget("2", target2Mock.Object);

            var eventDispatcher = new DefaultEventDispatcher(configuration);

            var loggingEvent = new LoggingEvent { Text = "Event" };
            var loggingEvents = new[] { loggingEvent };

            eventDispatcher.Push(loggingEvents);

            target1Mock.Verify(o => o.Push(loggingEvents));
            target2Mock.Verify(o => o.Push(loggingEvents));
        }
        public void Event_Complying_With_Level_Filters_Should_Be_Pushed()
        {
            var targetMock = new Mock<Target>();
            targetMock.SetupGet(x => x.MinLevel).Returns(LoggingEventLevel.Warning);
            targetMock.SetupGet(x => x.MaxLevel).Returns(LoggingEventLevel.Error);

            var loggingEvent = new LoggingEvent()
            {
                Level = LoggingEventLevel.Error
            };

            var configuration = new PulsusConfiguration();
            configuration.AddTarget("1", targetMock.Object);

            var eventDispatcher = new DefaultEventDispatcher(configuration);
            eventDispatcher.Push(new[] { loggingEvent });

            targetMock.Verify(x => x.Push(It.IsAny<LoggingEvent[]>()), Times.Once);
        }
        public void Event_Matching_LogKeyStartsWith_Ignore_Filter_Should_Be_Ignored()
        {
            var targetMock = new Mock<Target>();
            targetMock.SetupGet(x => x.Ignores).Returns(new List<Ignore>()
            {
                new Ignore() { LogKeyStartsWith = "Sample." }
            });

            var loggingEvent = new LoggingEvent()
            {
                LogKey = "Sample.LogKey"
            };

            var configuration = new PulsusConfiguration();
            configuration.AddTarget("1", targetMock.Object);

            var eventDispatcher = new DefaultEventDispatcher(configuration);
            eventDispatcher.Push(new[] { loggingEvent });

            targetMock.Verify(x => x.Push(It.IsAny<LoggingEvent[]>()), Times.Never);
        }
 public DefaultEventDispatcher(PulsusConfiguration configuration)
 {
     _configuration = configuration;
 }
        public void Event_Matching_TextContains_Ignore_Filter_Should_Be_Ignored()
        {
            var targetMock = new Mock<Target>();
            targetMock.SetupGet(x => x.Ignores).Returns(new List<Ignore>()
            {
                new Ignore() { TextContains = "description" }
            });

            var loggingEvent = new LoggingEvent()
            {
                Text = "A description of the error"
            };

            var configuration = new PulsusConfiguration();
            configuration.AddTarget("1", targetMock.Object);

            var eventDispatcher = new DefaultEventDispatcher(configuration);
            eventDispatcher.Push(new[] { loggingEvent });

            targetMock.Verify(x => x.Push(It.IsAny<LoggingEvent[]>()), Times.Never);
        }
        public void Event_Matching_TagContains_Ignore_Should_Be_Ignored()
        {
            var targetMock = new Mock<Target>();
            targetMock.SetupGet(x => x.Ignores).Returns(new List<Ignore>()
            {
                new Ignore() { TagsContains = "tag2" }
            });

            var loggingEvent = new LoggingEvent()
            {
                Tags = new List<string>() { "tag1", "tag2", "tag3", "tag4" }
            };

            var configuration = new PulsusConfiguration();
            configuration.AddTarget("1", targetMock.Object);

            var eventDispatcher = new DefaultEventDispatcher(configuration);
            eventDispatcher.Push(new[] { loggingEvent });

            targetMock.Verify(x => x.Push(It.IsAny<LoggingEvent[]>()), Times.Never);
        }