示例#1
0
        public void ForContextAddingPropertiesTests()
        {
            var dummySink = new DummySink();
            var log       = new SerilogLogger(new LoggerConfiguration().WriteTo.Sink(dummySink).CreateLogger());

            var messageTemplate = "Testing adding {prop2} props";

            log.ForContext("prop", "value").InfoFormat(messageTemplate, "awesome");
            Log.CloseAndFlush();

            var result = dummySink.Events.SingleOrDefault();

            Assert.NotNull(result);
            Assert.AreEqual(LogEventLevel.Information, result.Level);
            Assert.AreEqual(messageTemplate, result.MessageTemplate.Text);
            Assert.True(result.Properties.ContainsKey("prop"));
            Assert.AreEqual("\"value\"", result.Properties["prop"].ToString());
            Assert.True(result.Properties.ContainsKey("prop2"));
            Assert.AreEqual("\"awesome\"", result.Properties["prop2"].ToString());
        }