简体   繁体   English

为什么每个人都使用带有 ASP.Net Core 的 ILogger 的记录器包?

[英]Why everyone using logger packages with ILogger of ASP.Net Core?

for logging, developers use from logging package like: Nlog, SeriLog, ... while asp.net core has Microsoft.Extenstions.Logging.ILogger ?对于日志记录,开发人员使用 package 日志记录,例如:Nlog,SeriLog,... 而 asp.net 核心具有Microsoft.Extenstions.Logging.ILogger

doesn't ILogger of asp.net core recording log? asp.net核心记录日志的ILogger不是吗?

if ILogger can records log, isn't better uses that without any other packages?如果ILogger可以记录日志,不使用任何其他软件包不是更好吗? if ILogger can records log, then why developers don`t use it alone?如果ILogger可以记录日志,那为什么开发者不单独使用呢?

and if ILogger can't records log alone and other packages do, then what is benefits of ILogger that being used with other logging packages together instead using one logging package alone?如果ILogger不能单独记录日志而其他程序包可以,那么ILogger与其他日志记录程序包一起使用而不是单独使用一个日志记录 package 有什么好处?

By default ASP.NET Core using the Microsoft.Extensions.Logging.ILogger .默认情况下 ASP.NET 核心使用Microsoft.Extensions.Logging.ILogger

So call CreateDefaultBuilder, which adds the following logging providers:因此调用 CreateDefaultBuilder,它会添加以下日志记录提供程序:

  • Console安慰
  • Debug调试
  • EventSource事件源
  • EventLog: Windows only事件日志:仅 Windows

code example:代码示例:

Host.CreateDefaultBuilder(args)
    .ConfigureWebHostDefaults(webBuilder =>
                 {
                     webBuilder.UseStartup<Startup>();
                 });

source: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-3.1来源: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-3.1

So generally speaking every project has its own requirements and needs, so the developer can choose which one is more fit to project needs.所以一般来说每个项目都有自己的需求和需求,所以开发者可以选择哪个更适合项目需求。 Other logger providers like Nlog, SeriLog, Asure, ... can provide different log themes, flexible configurations, log in to file, and other features that the default ASP.NET Core not have. Nlog、SeriLog、Asure 等其他记录器提供程序可以提供不同的日志主题、灵活的配置、登录到文件以及默认 ASP.NET 内核不具备的其他功能。 The ILogger and ILoggerProvider interfaces and installation of additional packages have the flexibility to add other logger providers. ILogger 和 ILoggerProvider 接口和附加包的安装可以灵活地添加其他记录器提供程序。

ILoggerProvider Interface https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.iloggerprovider?view=dotnet-plat-ext-3.1 ILoggerProvider 接口https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.iloggerprovider?view=dotnet-plat-ext-3.1

Hope I`m answered well.希望我得到很好的回答。

From https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-3.1来自https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-3.1

.NET Core supports a logging API that works with a variety of built-in and third-party logging providers. .NET Core 支持日志记录 API,可与各种内置和第三方日志记录提供程序一起使用。 This article shows how to use the logging API with built-in providers.本文展示了如何将日志记录 API 与内置提供程序一起使用。

This gives you flexibility and additional features.这为您提供了灵活性和附加功能。

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

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