【问题标题】:How do I set Properties for Seq in my appsettings.json file?如何在我的 appsettings.json 文件中设置 Seq 的属性?
【发布时间】:2019-04-25 09:49:04
【问题描述】:

在我的 seq 日志中没有设置属性,我找不到通过 appsettings.json 设置它们的方法。我可以用方法设置它们

.Enrich.WithProperty("App", "缺席服务")

但对于 dotnet 核心依赖注入,我希望它在 appsettings.json 中设置,如下所示:

"Seq": {
  "ServerUrl": "xxxx",
  "ApiKey": "xxxx",
  "MinimumLevel": "Warning",
  "LevelOverride": {
  "Microsoft": "Error"
  }
}

如何在 appsettings.json 中设置应用或环境等属性?

【问题讨论】:

    标签: .net-core appsettings seq


    【解决方案1】:

    您可以在应用程序启动时将 appsettings 配置值写入记录器配置。

    var logConfig = new LoggerConfiguration()
        .WriteTo.Seq(Configuration.GetValue<string>("Seq:ServerUrl"),
            apiKey: Configuration.GetValue<string>("Seq:ApiKey"),
            bufferBaseFilename: Configuration.GetValue<string>("Seq:BufferFilename"),
            controlLevelSwitch: levelSwitch);
    

    您的配置格式看起来可以正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多