How to log queries using Entity Framework 7?

前端 未结 10 1533
清歌不尽
清歌不尽 2020-12-15 23:55

I am using Entity Framework 7 on the nightly build channel (right now I\'m using version EntityFramework.7.0.0-beta2-11524) and I\'m trying to log the queries that EF genera

10条回答
  •  感动是毒
    2020-12-16 00:17

    You can log to the console using this code, I am sure it will be wrapped in a simpler api later:

    using System;
    using Microsoft.Data.Entity.Infrastructure;
    using Microsoft.Data.Entity.Utilities;
    using Microsoft.Framework.Logging;
    
    public static class SqlCeDbContextExtensions
    {
        public static void LogToConsole(this DbContext context)
        {
            var loggerFactory = ((IAccessor)context).GetService();
            loggerFactory.AddProvider(new DbLoggerProvider());
        }
    }
    

    And the DbLoggerProvider is implemented here: https://github.com/ErikEJ/EntityFramework7.SqlServerCompact/tree/master/src/Provider40/Extensions/Logging

提交回复
热议问题