コード例 #1
0
        public async Task Sends_message_to_Graylog(LogLevel logLevel, int expectedLevel)
        {
            var messageText = Faker.Lorem.Sentence();
            var sut         = LoggerFixture.CreateLogger <GelfLoggerTests>();

            sut.Log(logLevel, new EventId(), (object)null, null, (s, e) => messageText);

            var message = await GraylogFixture.WaitForMessageAsync();

            Assert.NotEmpty(message._id);
            Assert.Equal(LoggerFixture.LoggerOptions.LogSource, message.source);
            Assert.Equal(messageText, message.message);
            Assert.Equal(expectedLevel, message.level);
            Assert.Equal(typeof(GelfLoggerTests).FullName, message.logger);
            Assert.Throws <RuntimeBinderException>(() => message.exception);
        }
コード例 #2
0
        public async Task Sends_message_with_and_without_compression(int compressionThreshold, int messageSize)
        {
            var options = LoggerFixture.LoggerOptions;

            options.UdpCompressionThreshold = compressionThreshold;
            var messageText = new string('*', messageSize);

            using var loggerFactory = LoggerFixture.CreateLoggerFactory(options);
            var sut = loggerFactory.CreateLogger(nameof(GelfLoggerTests));

            sut.LogInformation(messageText);

            var message = await GraylogFixture.WaitForMessageAsync();

            Assert.NotEmpty(message._id);
            Assert.Equal(options.LogSource, message.source);
            Assert.Equal(messageText, message.message);
            Assert.Equal(6, message.level);
        }