-
-
Save elanderson/1eb1c2452e1d8b5a3b5b to your computer and use it in GitHub Desktop.
Configure EF7 to Log to the Console
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment