Exemple #1
0
        public void Logs_are_discarded_if_formatter_returns_null([Frozen] ILogglyProcessor processor, LogglyLogger sut, LogLevel level, EventId eventId, object state, Exception error)
        {
            Func <object, Exception, string> formatter = (s, ex) => null;

            sut.Log(level, eventId, state, error, formatter);

            Mock.Get(processor).Verify(p => p.EnqueueMessage(It.IsAny <LogglyMessage>()), Times.Never);
        }
Exemple #2
0
        public void Logs_are_packed_into_LogglyMessage([Frozen] ILogglyProcessor processor, LogglyLogger sut, LogLevel level, EventId eventId, object state, Exception error, Func <object, Exception, string> formatter, string message)
        {
            Mock.Get(formatter).Setup(p => p(It.IsAny <object>(), It.IsAny <Exception>())).Returns(message);

            sut.Log(level, eventId, state, error, formatter);

            Mock.Get(processor).Verify(p => p.EnqueueMessage(It.Is <LogglyMessage>(m => m.Level == level && m.Category == sut.Name && m.Event == eventId && m.Data == state && m.Message == message)));
        }
Exemple #3
0
        public void Logs_are_discarded_if_not_matching_filter([Frozen] ILogglyProcessor processor, [Frozen] LogglyOptions options, LogglyLogger sut, LogLevel level, EventId eventId, object state, Exception error, Func <object, Exception, string> formatter)
        {
            options.Filter = (name, id, logLevel) => false;

            sut.Log(level, eventId, state, error, formatter);

            Mock.Get(processor).Verify(p => p.EnqueueMessage(It.IsAny <LogglyMessage>()), Times.Never);
        }
Exemple #4
0
        public void Logs_from_LogglyHttpClient_are_ignored(ILogglyProcessor processor, LogglyOptions options, LogLevel level, EventId eventId, object state, Exception error, Func <object, Exception, string> formatter)
        {
            var sut = new LogglyLogger(typeof(LogglyHttpClient).FullName, processor, options);

            sut.Log(level, eventId, state, error, formatter);

            Mock.Get(processor).Verify(p => p.EnqueueMessage(It.IsAny <LogglyMessage>()), Times.Never);
        }
Exemple #5
0
        public void Messages_can_be_pre_processed([Frozen] ILogglyProcessor processor, [Frozen] LogglyOptions options, LogglyLogger sut, LogLevel level, EventId eventId, object state, Exception error, Func <object, Exception, string> formatter)
        {
            sut.Log(level, eventId, state, error, formatter);

            Mock.Get(options.PreProcessMessage).Verify(p => p(It.IsAny <LogglyMessage>()), Times.Once);
        }
Exemple #6
0
        public void No_error_is_added_to_message_when_exception_is_null([Frozen] ILogglyProcessor processor, LogglyLogger sut, LogLevel level, EventId eventId, object state, Func <object, Exception, string> formatter)
        {
            sut.Log(level, eventId, state, null, formatter);

            Mock.Get(processor).Verify(p => p.EnqueueMessage(It.Is <LogglyMessage>(o => o.Error == null)));
        }
Exemple #7
0
        public void Dispose_disposes_the_processor([Frozen] ILogglyProcessor processor, LogglyLoggerProvider sut)
        {
            sut.Dispose();

            Mock.Get(processor).Verify(p => p.Dispose());
        }
 public LogglyLoggerProvider(ILogglyProcessor processor, LogglyOptions options)
 {
     _processor = processor ?? throw new ArgumentNullException(nameof(processor));
     _options   = options ?? throw new ArgumentNullException(nameof(options));
 }
 public LogglyLogger(string name, ILogglyProcessor processor, LogglyOptions options)
 {
     _processor = processor ?? throw new ArgumentNullException(nameof(processor));
     _options   = options ?? throw new ArgumentNullException(nameof(options));
     Name       = name ?? throw new ArgumentNullException(nameof(name));
 }