Entity framework core 2 SQL is always logged

Viewed 837

After upgrading to asp.net + entity framework core 2 i noticed something weird. Before (in 1.1), i had to use DbContextOptionsBuilder.UseLoggerFactory to log SQL queries that were produced by ef, but now, i don't have to do it anymore, SQL queries are logged by default.

The logger factory is set to "Information"

loggerFactory.AddFile("Logs/MyApp-{Hour}.txt", LogLevel.Information);

Shouldn't SQL queries be associated with Debug? is it normal? is there a way to keep the logging level Information and disabling just the SQL logging?

1 Answers

I found out that entity framework is supposed to log SQL in "Information" I changed the loggerFactory to

loggerFactory.AddFile("Logs/MyApp-{Hour}.txt", LogLevel.Information, new Dictionary<string, LogLevel>()
            {
                { "Microsoft", LogLevel.Error },
                { "System", LogLevel.Error }
            });

So that everything with "Microsoft" or "System" in it's namespace would log only Errors (or anything above)

Related