logging - 如何配置 ILogger 以将日志输出到特定文件?

标签 logging asp.net-core asp.net-core-2.0

我有一个 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/

相关文章:

c# - 将 ASP.NET MVC 5 项目迁移到 ASP.NET 5

java - 如何在 mulesoft 表达式组件中使用 log4j2 属性

logging - LoggerFactory 与 Logger

asp.net - 是否等效于ASP.NET Core MVC中的 “@section”?

.net - 从 .Net Core 2.0 项目引用 .Net framework 4.5.2

c# - .NET Core 2 - EF Core 错误处理保存更改

javascript - 如何将页面特定的js注入(inject)_Layout

Java 日志记录似乎不适用于 FINE/FINER/FINEST 级别

c# - 最小化生产中的日志语句

.net - IMediatR - 通用请求的通用请求处理程序