Interceptors (EF6.1 Onwards)

Starting with EF6.1 you can register interceptors in the config file. Interceptors allow you to run additional logic when EF performs certain operations, such as executing database queries, opening connections, etc.

Interceptors are registered by including an interceptor element under the interceptors child section of the entityFramework section. For example, the following configuration registers the built-in DatabaseLogger interceptor that will log all database operations to the Console.

<interceptors> 
  <interceptor type="System.Data.Entity.Infrastructure.Interception.DatabaseLogger, EntityFramework"/> 
</interceptors>

Logging Database Operations to a File (EF6.1 Onwards)

Registering interceptors via the config file is especially useful when you want to add logging to an existing application to help debug an issue.DatabaseLogger supports logging to a file by supplying the file name as a constructor parameter.

<interceptors> 
  <interceptor type="System.Data.Entity.Infrastructure.Interception.DatabaseLogger, EntityFramework"> 
    <parameters> 
      <parameter value="C:\Temp\LogOutput.txt"/> 
    </parameters> 
  </interceptor> 
</interceptors>

By default this will cause the log file to be overwritten with a new file each time the app starts. To instead append to the log file if it already exists use something like:

<interceptors> 
  <interceptor type="System.Data.Entity.Infrastructure.Interception.DatabaseLogger, EntityFramework"> 
    <parameters> 
      <parameter value="C:\Temp\LogOutput.txt"/> 
      <parameter value="true" type="System.Boolean"/> 
    </parameters> 
  </interceptor> 
</interceptors>

For additional information on DatabaseLogger and registering interceptors, see the blog post EF 6.1: Turning on logging without recompiling.

记录entityframework生成的sql语句的更多相关文章

  1. .net core 利用日志查看ef生成的SQL语句

    EF Core 没有直接提供像 EF6 那样方便的在日志中记录最终生成的 SQL 的功能,可以通过官方提供的日志记录(Microsoft.Extensions.Logging)实现. 一. 使用 Mi ...

  2. 深入理解 LINQ to SQL 生成的 SQL 语句

    Ø  简介 在 C# 中与数据交互最常用的语句就是 LINQ 了,而 LINQ to SQL 是最直接与数据库打交道的语句,它可以根据 LINQ 语法生成对应的 SQL 语句,在数据库中去执行.本文主 ...

  3. 监听Entity Framework生成的Sql语句

               Entity Framework为我们提供了很大的方便,但有时候,我们想看看EF生成的Sql语句到底是怎样的,一种方式是我们可以启用Sql Server Profer工具.今天介 ...

  4. 用PowerDesign反向生成数据库Sql语句问题

            在用Pd15反向生成数据库时,生成的Sql语句在Sql Server Manager Studio里面报错,根本就执行不了.数据库用的是Sql Server 2008 R2.经过一番修 ...

  5. 将EntityFrameworkCore生成的SQL语句输出到控制台,使用hangfire

    将EntityFrameworkCore生成的SQL语句输出到控制台 参考文档如下 EF Core 日志记录要求使用一个或多个日志记录提供程序配置的 ILoggerFactory. 日志记录-EF C ...

  6. EntityFramework中使用sql语句

    https://blog.csdn.net/yangyangafan/article/details/77602133 EntityFramework操作数据库谜一般的方便还不用写数据库,但前提是很简 ...

  7. 使用EntityFramework6.1的DbCommandInterceptor拦截生成的SQL语句

    开始 EF6.1也出来不少日子了,6.1相比6.0有个很大的特点就是新增了System.Data.Entity.Infrastructure.Interception 命名空间,此命名空间下的对象可以 ...

  8. 用LinqPad查看Nhibernate生成的sql语句

    使用Nhibernate开发一般都要对Nhibernate生成的sql语句进行查看及分析,查看Nhibernate生成的sql语句,可以使用NHProfiler和log4net.但NHProfiler ...

  9. 【转】Hibernate利用@DynamicInsert和@DynamicUpdate生成动态SQL语句

    原文链接:http://www.cnblogs.com/quanyongan/p/3152290.html 最近在使用Hibernate4中,发现两个很有奥秘的注解 @DynamicInsert 和  ...

随机推荐

  1. 最长公共子序列LCS(POJ1458)

    转载自:https://www.cnblogs.com/huashanqingzhu/p/7423745.html 题目链接:http://poj.org/problem?id=1458 题目大意:给 ...

  2. STM32 --- 什么时候打开复用IO的时钟(比如RCC_APB2Periph_AFIO)

    需要用到外设的重映射功能时才需要使能AFIO的时钟,包括外部中断. 外部中断(EXTI)中与AFIO有关的寄存器是AFIO-EXTICR1.2.3,它们是用来选择EXTIx外部中断的输入脚之用. 举例 ...

  3. Object.keys()返回对象的属性

    <script> // 传入对象,返回属性名 let obj = { 'a': '123', 'b': '456' } console.log(Object.keys(obj)) //[& ...

  4. spring boot 2.0.3+spring cloud (Finchley)2、搭建负载均衡Ribbon (Eureka+Ribbon+RestTemplate)

    Ribbon是Netflix公司开源的一个负载均衡组件,将负载均衡逻辑封装在客户端中,运行在客户端的进程里. 本例子是在搭建好eureka的基础上进行的,可参考spring boot 2.0.3+sp ...

  5. PB9.0数据窗口入门

    因为工作的关系,最近公司用PB比较多,至少10年没用过PB了,回顾一下数据窗口使用方法.1.代码结构 2.数据窗口 3.代码窗口代码 APP入口代码 4.需要使用DataBase插入一条数据 5.执行 ...

  6. Bugly实现app全量更新

    转 http://blog.csdn.net/qq_33689414/article/details/54911895Bugly实现app全量更新 Bugly官网文档 一.参数配置 在app下的gra ...

  7. Jacob 调用金税系统

    1.调用打印方法时,若是有预览弹窗提示,程序会阻塞住,并在控制台打印一行: C:\Program Files (x86)\��Ʊ���\914601007603699430.0\Config\Prin ...

  8. 三、内存管理单元---MMU

    3.1 MMU介绍 3.1.1 MMU 特性 内存管理单元(Memory Management Unit)简称MMU,它负责虚拟地址到物理地址的映射,并提供硬件机制的内存访问权限检查.现在的多用户多进 ...

  9. C# 面向对象的base的使用

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...

  10. 第18月第21日 vue cnpm

    1. 首先我们需要下载npm,因为我已经提前安装了node.js,安装包里面集成了npm,然后我们就可以利用npm命令从获取淘宝镜像的cnpm了. 1.打开命令行窗口,输入 npm install - ...