【发布时间】:2021-10-28 21:01:54
【问题描述】:
有没有办法做到这一点? 我想通过读取 appsettings.json 的设置来更改最低日志记录级别
我的代码是这样的
Serilog.Log.Logger = new LoggerConfiguration()
.Enrich.WithExceptionDetails()
.MinimumLevel.Verbose()
.WriteTo.Console()
.Enrich.WithProperty("Application", applicationName)
.WriteTo.File(new JsonFormatter(renderMessage: true), "logs/myapp.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
【问题讨论】:
-
嗯,你试过什么?你读过文档吗?
-
我知道如何从 appsettings.json 文件中读取值 - 但我不确定如何传入它,因为它不是枚举
-
这应该有你需要的一切。 nblumhardt.com/2016/03/…
-
向我们展示您的尝试:)
-
我用这段代码获取了applicationName: