Esempio n. 1
0
        static void Main(string[] args)
        {
            Serilog.Debugging.SelfLog.Enable(Console.Error);

            var config = new RedisStreamSinkConfiguration
            {
                RedisConnectionString = "redis:6379",
                RedisStreamName       = "ExampleApp"
            };

            Console.WriteLine("Logging configuration set.");
            Console.WriteLine(JsonConvert.SerializeObject(config));

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Information()
                         .Enrich.WithProperty("Version", "1.0.0")
                         .WriteTo.RedisStreamSink(config)
                         .CreateLogger();
            Console.WriteLine("Logger created.");

            try
            {
                Log.Information("Completed log test to Redis Streams.");
                Console.WriteLine("Log entry written.");
            }

            catch (Exception ex)
            {
                Console.WriteLine("failed to log");
                Console.WriteLine(ex);
            }
        }
Esempio n. 2
0
        public void SinkConfig_MessageFieldDefaultedIfNotSet()
        {
            var config = new RedisStreamSinkConfiguration
            {
                RedisConnectionString = "localhost:3267",
                RedisStreamName       = "ExampleApp"
            };

            Assert.Equal("message", config.RedisStreamMessageField);
        }
Esempio n. 3
0
        public void SinkConfig_AutoPropertiesSetCorrectly()
        {
            var config = new RedisStreamSinkConfiguration
            {
                RedisConnectionString   = "a",
                RedisStreamName         = "b",
                RedisStreamMessageField = "c"
            };

            Assert.Equal("a", config.RedisConnectionString);
            Assert.Equal("b", config.RedisStreamName);
            Assert.Equal("c", config.RedisStreamMessageField);
        }
Esempio n. 4
0
        public void RedisConnection_ConfigurationConnectionMissing()
        {
            var config1 = new RedisStreamSinkConfiguration
            {
                RedisConnectionString = null
            };
            var sink1 = new RedisStreamSink(config1, null);

            Assert.Throws <NullReferenceException>(() => sink1.ConnectToRedis());

            var config2 = new RedisStreamSinkConfiguration
            {
                RedisConnectionString = ""
            };
            var sink2 = new RedisStreamSink(config2, null);

            Assert.Throws <NullReferenceException>(() => sink2.ConnectToRedis());
        }
Esempio n. 5
0
        public void SuccessfulLogger()
        {
            var config = new RedisStreamSinkConfiguration
            {
                RedisConnectionString   = "a",
                RedisStreamName         = "b",
                RedisStreamMessageField = "c"
            };

            string          outputTemplate = "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff} {Level:u3}] {Message:lj}{NewLine}{Exception}";
            IFormatProvider formatProvider = null;
            var             formatter      = new Serilog.Formatting.Display.MessageTemplateTextFormatter(outputTemplate, formatProvider);
            var             template       = new MessageTemplateParser().Parse("{TestToken} is good");
            var             properties     = new List <LogEventProperty> {
                new LogEventProperty("TestToken", new ScalarValue("Ice Cream"))
            };

            var mockDatabase    = BuildDatabase("SUCCESS_ID");
            var mockMultiplexer = BuildSuccessConnectionMultiplexer(mockDatabase);
            var mockSink        = new Mock <RedisStreamSink>(config, formatter)
            {
                CallBase = true
            };

            mockSink.Setup(_ => _.ConnectToRedis())
            .Returns(mockMultiplexer.Object);

            var loggingEvent = new LogEvent(DateTimeOffset.Now,
                                            LogEventLevel.Information,
                                            null,
                                            template,
                                            properties);

            mockSink.Object.Emit(loggingEvent);

            Assert.True(true);
        }