I'm looking at my application log stream in Azure for an asp.net core 2 EF core web api and am getting bombarded by the message
Context 'Context' started tracking 'Model' entity. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see key values.
Is there any way to disable/suppress these messages without turning tracking off in my code?
Edit: Code from dbContextClass
public class Context : DbContext
{
public Context (DbContextOptions<Context> options)
: base(options)
{
}
public DbSet<Model> Model { get; set; }
/*protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// add your own confguration here
}*/
}
When you query the database for some record without using AsNoTracking
, EF Core will start tracking it in current context. AsNoTracking
is one solution as you don't want EF Core to track any modifications to that. In many cases not having AsNoTracking
is fine as long as you don't add/attach/update entity with same id in the context. But it is good to have it explicitly when tracking is not required.
For more details, you could refer to this article.
Also, the LogStartedTracking
field only support Entity Framework Core 2.1, you could try to upgrade your EF Core version.