.NET Core开发日志——结构化日志 (2)

与NLog相比,Serilog省去了配置文件,直接使用代码,实现方式更加简洁。

var position = new { Latitude = 25, Longitude = 134 }; var elapsedMs = 34; var log = new LoggerConfiguration() .WriteTo.Console(new JsonFormatter()) .CreateLogger(); log.Information("Processed {@Position} in {Elapsed:000} ms.", position, elapsedMs);

执行结果:

{"Timestamp":"2018-12-22T17:15:23.6389082+08:00","Level":"Information","MessageTemplate":"Processed {@Position} in {Elapsed:000} ms.","Properties":{"Position":{"Latitude":25,"Longitude":134},"Elapsed":34},"Renderings":{"Elapsed":[{"Format":"000","Rendering":"034"}]}}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zygppd.html