【发布时间】:2020-04-19 02:33:46
【问题描述】:
我正在将我的 C# .Net Core 3.1 应用程序从 log4net 移植到 Microsoft.Extensions.Logging。更新代码出奇地顺利,因此我能够像以前一样构建和运行应用程序。但是,我根本无法弄清楚如何查看任何日志记录输出!我有 Microsoft.Extensions.Logging 3.1.3 作为包依赖项。
例如,我可以使用 dotnet run 从控制台运行应用程序,但无法在控制台中显示任何日志记录。我已经尝试了很多代码:
ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder
.AddFilter("Microsoft", LogLevel.Debug)
.AddFilter("System", LogLevel.Debug)
.AddFilter("Namespace.Class", LogLevel.Debug)
.AddConsole()
);
ILogger logger = loggerFactory.CreateLogger("Namespace.Class");
logger.LogError("This is an error message.");
logger.LogInformation("This is an information message.");
logger.LogDebug("This is a debug message.");
但是,我在控制台中看不到任何日志记录输出。我也想将日志记录发送到文件,但也无法弄清楚如何执行此操作。欢迎任何让我入门的指导。
【问题讨论】:
-
删除过滤器会改变行为吗?
-
很遗憾没有,但感谢您的建议!