如何使EF核心迁移不再冗长

问题描述:

我正在使用Entity Framework Core 1.1.0进行迁移。当我运行它们时如何使EF核心迁移不再冗长

dotnet ef database update 

在包管理器控制台中,控制台充满了应用的SQL。与此相反,我想仅打印当前正在应用的迁移名称。我怎样才能做到这一点?

我假定你的项目的配置。

要禁用SQL打印试试这个

var builder = new DbContextOptionsBuilder<NAMEContext>(); 
builder.UseMySql(connectionString); 
builder.UseLoggerFactory(new MigrationLoggerFactory()); <--- this seems to be what you are looking for 
return new MigrationDataContext(builder.Options); 

MigrationLoggerFactory

public class MigrationLoggerFactory : ILoggerFactory 
    { 
     public void Dispose() { } 

     public ILogger CreateLogger(string categoryName) 
     { 
      if ("Microsoft.EntityFrameworkCore.Migrations".Equals(categoryName)) 
       return new MigrationLogger(); 

      return new NullLogger(); 
     } 

     public void AddProvider(ILoggerProvider provider) 
     { 
     } 
    } 

NullLogger

public class NullLogger : ILogger 
    { 
     public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter) 
     { 
      throw new NotImplementedException(); 
     } 

     public bool IsEnabled(LogLevel logLevel) 
     { 
      return false; 
     } 

     public IDisposable BeginScope<TState>(TState state) 
     { 
      return null; 
     } 
    } 

这里是一个article这也可能有帮助