我正在尝试使用 Serilog 将丰富的属性输出到呈现的消息中:
private static Tester GetTester()
{
return new Tester {Count = 7, Name = "Redmond"};
}
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.Enrich.WithProperty("Site", "Dan Local")
.WriteTo
.ColoredConsole()
.CreateLogger();
var tester = GetTester();
Log.Verbose("{Site} - This is verbose {@tester}", tester);
Log.Verbose("This is verbose {@tester} - {Site}", tester);
第一条日志语句输出:
2014-08-19 10:02:25 [Verbose] "SeriLogTest.Tester" - This is verbose {@tester}
第二条日志语句输出:
2014-08-19 10:02:25 [Verbose] This is verbose Tester { Count: 7, Name: "Redmond" } - "Dan Local"
我希望它们都输出相同的信息,只是按照消息模板定义的不同顺序。但是正如您所看到的,如果您没有将丰富的属性放在最后,它会被提供的要记录的对象接管,并且第二个模板属性将被忽略。有没有办法做到这一点?