serilog LoggerConfiguration通过webconfig

时间:2018-10-09 23:24:24

标签: serilog

如何使LoggerConfiguration通过Web.config(应用程序设置)(如Verbose / Debug等)进行管理。

Log.Logger = new LoggerConfiguration()
    .MinimumLevel.Verbose()// I want to make is configurable via web.config.
    .Enrich.FromLogContext()                    
    .WriteTo.Seq(serilogUrl)
    .CreateLogger();

1 个答案:

答案 0 :(得分:1)

使用Serilog.Settings.AppSettings

Log.Logger = new LoggerConfiguration()
  .ReadFrom.AppSettings()
  ... // Other configuration here, then
  .CreateLogger();

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="serilog:minimum-level" value="Verbose" />
    <!-- More settings here -->
  </appSettings>
</configuration>

Serilog的文档非常不错。你应该检查一下: https://serilog.net

enter image description here