Serilog是一个结构化的C#日志库。支持从配置初始化,
Log.Logger = new LoggerConfiguration() .ReadFrom.AppSettings() .CreateLogger();配置文件如下:
<add key="serilog:minimum-level" value="Verbose" /> <add key="serilog:write-to:RollingFile.pathFormat" value="D:\Users\TEMP\Robot-{Date}.txt" /> <add key="serilog:write-to:RollingFile.retainedFileCountLimit" value="10" />Nuget安装:
Install-Package Serilogvar position = new { Latitude = 25, Longitude = 134 };var elapsedMs = 34;log.Information("Processed {@Position} in {Elapsed:000} ms.", position, elapsedMs);{"Position": {"Latitude": 25, "Longitude": 134}, "Elapsed": 34}
评论