Hi you can do something like following to display Entity Framework Core generated sql code in output window.
In your DbContext
class:
public static readonly Microsoft.Extensions.Logging.LoggerFactory _myLoggerFactory =
new LoggerFactory(new[] {
new Microsoft.Extensions.Logging.Debug.DebugLoggerProvider()
});
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseLoggerFactory(_myLoggerFactory);
}
The debug logger writes messages in the debug output window only when a debugger is attached.
You will have to do following:
- using Microsoft.Extensions.Logging;
- Install nuget package: Microsoft.Extensions.Logging.Debug
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…