我有一个 ASP.NET Core 2 Web 应用程序正在部署到生产环境,需要启用日志来解决错误。我无法在文档中的任何地方找到 appsettings.json 的记录器部分中的架构。这是我在那里的东西:
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
},"Console": {
"IncludeScopes": "true"
}
}
当我从控制台运行 exe 时,日志信息显示在控制台中,但 Entity Framework 也在记录日志,因此由于显示的输出量有限,我看不到自己的消息。因此我需要将日志输出到一个文件,比如 C:\temp\my.log。如何配置 ASP.NET Core 2 来执行此操作?
提前致谢。
最佳答案
Thus I need to output the logs to a file, say C:\temp\my.log. How can I configure ASP.NET Core 2 to do this?
Serilog 有 a package for that .
dotnet add package Serilog.Extensions.Logging.File
我们是这样配置的。
public void ConfigureServices(IServiceCollection services)
{
services.AddLogging();
}
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
loggerFactory.AddFile("C:\\temp\\my.log");
}
另见:https://nblumhardt.com/2016/10/aspnet-core-file-logger/
关于logging - 如何配置 ILogger 以将日志输出到特定文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51886315/