How to make EF Core migrations less verbose
Asked Answered
Q

1

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?

Quoth answered 5/9, 2017 at 7:32 Comment(0)
B
0

I assume its configuration of your project.

To disable sql print try this

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

Here is an article which could also be helpful

Brazilein answered 14/9, 2017 at 4:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.