简体   繁体   English

在哪里可以找到用于配置Microsoft扩展日志记录的日志记录设置的文档?

[英]Where can I find the documentation for configuring the logging settings for Microsoft extension logging?

Everywhere you can find example on with the default settings 您可以使用默认设置在任何地方找到示例

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  }
}

I'd like to know if there is more than that, for exmple if i can customize the format of the message like in NLOG layout attribute. 我想知道是否有更多,例如,如果我可以自定义消息的格式,如NLOG布局属性。

<target name="logfile" xsi:type="File" fileName="file.txt" layout="${date:format=yyyyMMddHHmmss} ${message}" />

The following answer might not be entirely accurate, since I'm not too familiar with ASP.NET Core Logging. 以下答案可能不完全准确,因为我对ASP.NET核心日志不太熟悉。 The following is based on some research and looking at source code and examples. 以下是基于一些研究并查看源代码和示例。

A quick look at the source code of the Microsoft.Extensions.Logging NuGet package (whose source code can be found on GitHub ) reveals that the settings you're showing might be specific to the ConsoleLogger , which doesn't recognize any other settings. 快速浏览一下Microsoft.Extensions.Logging NuGet包的源代码(其源代码可以在GitHub上找到 ),可以看出您显示的设置可能特定于ConsoleLogger ,而ConsoleLogger无法识别任何其他设置。 See for yourself by looking at the source files here , especially the file ConfigurationConsoleLoggerSettings.cs where you'll find which configuration sections are accessed. 通过查看此处的源文件,亲自查看 ,尤其是文件ConfigurationConsoleLoggerSettings.cs ,您可以在其中找到访问的配置节。

Different loggers might take completely different approaches to read their configuration. 不同的记录器可能采用完全不同的方法来读取其配置。 For example, NLog can be configured with an XML file. 例如,NLog可以配置XML文件。 If you want to use NLog, you need to register the appropriate log provider with ASP.NET Core. 如果要使用NLog,则需要使用ASP.NET Core注册相应的日志提供程序。 You want the NLog provider . 你想要NLog提供商 There's an example project on that project page that demonstrates its basic use: 该项目页面上有一个示例项目 ,演示了它的基本用法:

// add the NuGet package `NLog.Web.AspNetCore` as a project dependency,
// which makes these namespaces available: 
using NLog.Extensions.Logging;
using NLog.Web;

// your ASP.NET Core startup / configuration class:
partial class Startup
{
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        …
        loggerFactory.AddNLog();
        app.AddNLogWeb();
        …
    }
}

Then configure NLog through the NLog.config XML file . 然后通过NLog.config XML文件配置NLog

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM