2
我是Serilog的新手,只有在需要時才顯示類名,而不必將{SourceContext:l}
添加到每條日誌消息中,是否可以在Serilog中只顯示SourceContext?我知道我可以只寫代碼:如果已經定義了ForContext <class>
Log.ForContext<Class1>().Verbose("message {SourceContext:l}");
我有如下記錄器被設置:
var log = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo
.ColoredConsole(outputTemplate: "{Timestamp:G} [{Level}] {SourceContext} {Message}{NewLine:l}{Exception:l}")
.CreateLogger();
我希望只有類的名字時已經指定的類顯示如這裏所見。
Log.ForContext<Class1>().Verbose("message");
而且如果創建日誌時不顯示。
Log.Verbose("message");
但是在上面的例子中,將打印日誌出 「{} SourceContext消息」的格式,而不是它是不是我想要的只是「消息」。