This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RequestResponseLoggingMiddleware | |
{ | |
private readonly RequestDelegate _next; | |
private readonly ILogger _logger; | |
public RequestResponseLoggingMiddleware(RequestDelegate next, | |
ILoggerFactory loggerFactory) | |
{ | |
_next = next; | |
_logger = loggerFactory |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class DbContextExtensions | |
{ | |
public static void LogToConsole(this DbContext context) | |
{ | |
IServiceProvider contextServices = ((IDbContextServices)context).ScopedServiceProvider; | |
var loggerFactory = contextServices.GetRequiredService<ILoggerFactory>(); | |
loggerFactory.AddConsole(LogLevel.Verbose); | |
} | |
} |