【发布时间】:2017-09-10 13:23:45
【问题描述】:
我似乎无法在控制台中显示任何 Debug 或 Trace 语句。
在Startup.csConfigure(...) 我有:
loggerFactory
.WithFilter(
new FilterLoggerSettings
{
{"AssetTrader", LogLevel.Debug},
{"Microsoft", LogLevel.Warning},
{"System", LogLevel.Warning},
})
.AddConsole();
在我的控制器动作中:
this._logger.LogTrace("Trace");
this._logger.LogDebug("Debug");
this._logger.LogInformation("Info");
this._logger.LogWarning("Warn");
但控制台输出只显示两个条目:
info: AssetTrader.Controllers.HomeController[0]
Info
warn: AssetTrader.Controllers.HomeController[0]
Warn
我也尝试过简单的loggerFactory.AddConsole(LogLevel.Debug),结果相同。
重现问题的简单测试项目的要点:https://gist.github.com/modo-lv/66e3209f89e986423397928630ba5f9a
【问题讨论】:
-
也许你被 appsettings.json 日志配置覆盖了?
-
尚未使用 appsettings.json。
-
你使用asp.net core 2.0吗?你能把你的代码放在github或gist上吗?还是这里有更多代码?
-
@nemke 添加了 gist URL。
-
请查看我的回答here。在 ASP.NET Core 2.0 中注册日志记录的方式发生了一些变化
标签: c# asp.net logging asp.net-core