[英]Entity Framework interceptor for log Debug.Write web.config
I want to create a Debug.Write logger on my project while development time. 我想在开发时在项目上创建Debug.Write记录器。 So I can do this on code configuration like this:
所以我可以在这样的代码配置上做到这一点:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
Action<string> print = message => Debug.WriteLine(message);
Database.Log =print;
}
But I want to add this on web.config file as entity framework section element. 但是我想在web.config文件中将其添加为实体框架部分元素。 Is there any way to do this?
有什么办法吗?
<interceptors>
<interceptor type="System.Data.Entity.Infrastructure.Interception.DatabaseLogger, EntityFramework">
??????
</interceptor>
</interceptors>
You can configure the interceptor either by using config file or code-based configuration. 您可以使用配置文件或基于代码的配置来配置拦截器。
See the following on how to do this (includes demo): 有关如何执行此操作的信息,请参见以下内容(包括演示):
http://www.entityframeworktutorial.net/entityframework6/database-command-interception.aspx http://www.entityframeworktutorial.net/entityframework6/database-command-interception.aspx
Assuming you have the following interceptor 假设您具有以下拦截器
EFCommandInterceptor: IDbCommandInterceptor
Config 设定档
<entityFramework>
<interceptors>
<interceptor type="EF6DBFirstTutorials.EFCommandInterceptor, EF6DBFirstTutorials">
</interceptor>
</interceptors>
</entityFramework>
Code 码
public class EF6CodeConfig : DbConfiguration
{
public EF6CodeConfig()
{
this.AddInterceptor(new EFCommandInterceptor());
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.