0
votes

I understand that ASP.NET Core uses Microsoft.Extension.Logging for logging. According to the official document, the default ASP.NET Core project templates call CreateDefaultBuilder, which adds the following logging providers:

  • Debug,
  • Console
  • EventSource
  • EventLog

But it never mentioned which provider will be used (used by the DI container to create the actual logger) by default. For example, if I have a class which calls _logger.LogError(ex, "ERROR", ex.Message) will the error message be sent to the Console, the Debug window, the EventLog system, or all of them? The advantage of using ASP.NET Core is that it liberates developers from writing tedious boilerplate code but at the same time, that also causes lots of confusion. How the LoggerFactory decides which loggerProvider to use in this case? If all of the registered providers are used, does that mean the DI container creates multiple logger instances for one ILogger interface?

1
The providers are essentially just listeners. Each provider can be filtered to only pay attention to certain log levels or namespace(s). When something is logged, each provider that is configured to handle that type of message, does its own thing. - Chris Pratt

1 Answers

0
votes

LoggerFactory is creating a logger with all providers in CreateLoggers()

then Logger would call log for all logger providers in Log(...)