Reputation: 6875
I want to create a Debug.Write logger on my project while development time. 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. Is there any way to do this?
<interceptors>
<interceptor type="System.Data.Entity.Infrastructure.Interception.DatabaseLogger, EntityFramework">
??????
</interceptor>
</interceptors>
Upvotes: 0
Views: 965
Reputation: 5312
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
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());
}
}
Upvotes: 1