如何在不appsetting.json的情况下配置日志记录?

发布于 2025-01-25 07:21:16 字数 702 浏览 3 评论 0原文

我正在研究.NET Framework 4.7.2 Web API,该API没有AppSetting.json。 我想知道我应该在哪里为Microsoft.extension.logging配置以下设置?

"Logging": {
    "LogLevel": {
        "Default": "Information",
        "Microsoft": "Warning",
        "Microsoft.Hosting.Lifetime": "Information"
}

并将其绑定到启动时的loggerfilteroption?

下面似乎不起作用:

LoggerFilterOptions options = new LoggerFilterOptions();
var config = UnityConfig.Container.Resolve<IConfiguration>();
config.GetSection("Logging").Bind(options);

我想控制minLoglevel规则(loggerfilteroption)通过web.config,可以实现吗?

I am working on .net framework 4.7.2 web API which doesn't have appsetting.json.
I wonder where should I configure the below setting for Microsoft.Extension.Logging?

"Logging": {
    "LogLevel": {
        "Default": "Information",
        "Microsoft": "Warning",
        "Microsoft.Hosting.Lifetime": "Information"
}

and Bind it to LoggerFilterOption on Startup?

Below seems not to work:

LoggerFilterOptions options = new LoggerFilterOptions();
var config = UnityConfig.Container.Resolve<IConfiguration>();
config.GetSection("Logging").Bind(options);

I want to control MinLogLevel and Rules (LoggerFilterOption)through the web.config, Can that be achieved?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文