7

I am using Entity Framework Core 1.1.0 with migrations. When I run them with

dotnet ef database update

in Package Manager Console the console is full of applied SQL. Instead of this, I would like to have printed only names of migrations that are currently being applied. How can I do this?

4

1 回答 1

0

我假设您的项目的配置。

要禁用 sql print 试试这个

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);

迁移记录器工厂

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)
        {
        }
    }

空记录器

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;
        }
    }

这是一篇也可能有帮助的文章

于 2017-09-14T04:37:15.517 回答