Ali Taheri
Ali Taheri

Reputation: 195

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 ?

doesn't ILogger of asp.net core recording log?

if ILogger can records log, isn't better uses that without any other packages? if ILogger can records log, then why developers don`t use it alone?

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?

Upvotes: 6

Views: 5080

Answers (2)

Sergei
Sergei

Reputation: 315

By default ASP.NET Core using the Microsoft.Extensions.Logging.ILogger.

So call CreateDefaultBuilder, which adds the following logging providers:

  • Console
  • Debug
  • EventSource
  • EventLog: Windows only

code example:

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

source: https://learn.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. The ILogger and ILoggerProvider interfaces and installation of additional packages have the flexibility to add other logger providers.

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

Hope I`m answered well.

Upvotes: 8

Bernard Vander Beken
Bernard Vander Beken

Reputation: 5056

From https://learn.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. This article shows how to use the logging API with built-in providers.

This gives you flexibility and additional features.

Upvotes: 2

Related Questions