In accordance with https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging, the proposed method of use Microsoft.Extensions.Loggingis represented through the injection of object dependencies ILogger.
Microsoft.Extensions.Logging
ILogger
What is the proposed pattern in situations where dependency injection does not work (or does not work), for example, in extension methods, type initializers, static properties, and other static members, where the transfer ILoggerwill be very cumbersome?
With log4net (which my command used to), a generic template looks like this:
public static class SomeExtensions { private static readonly ILog s_log = LogManager.GetLogger(typeof(SomeExtensions)); public static void ExtensionMethod (this SomeType someType) { s_log.Info("..."); } }
Is there a similar installed or recommended template with Microsoft.Extensions.Logging?
DI . - . ASP.NET (HttpContext, -?), . ASP.NET Core 100% DI.
HttpContext
, , . . , , , . , , singleton scope, .
, , - . , , , , . , , , . , , , . , , , , , : .. - , . .
, , . , , .