【EntityFramework优化:SQL语句日志】教程文章相关的互联网学习教程文章

EntityFramework日志记录【代码】

首先在应用启动时执行:DbInterception.Add(new LogFormatter()); 然后加入如下类:#region [ EF的数据库执行日志记录 ]publicclass LogFormatter : IDbCommandInterceptor{privatereadonly Stopwatch _stopwatch = new Stopwatch();publicvoid NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<int> interceptionContext){_stopwatch.Restart();}publicvoid NonQueryExecuted(DbCommand command, DbCommandInt...

EntityFramework优化:SQL语句日志

System; using System.Collections.Generic; using System.Linq; using System.Web;using System.Text; using System.Data.Entity.Infrastructure.Interception; using System.Diagnostics; using System.Data.Common;using NLog;namespace Libing.Portal.Web.Common.Interceptors {public class NLogDbCommandInterceptor : DbCommandInterceptor{private static readonly Stopwatch watch = new Stopwatch();private static read...