如何在appsettings.json文件中为Seq设置属性?

问题描述 投票:0回答:1

在我的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个回答
0
投票

您可以在应用程序启动时将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);

您的配置格式看起来会很好。

© www.soinside.com 2019 - 2024. All rights reserved.