title: Can I configure an interceptor in EntityFramework Core?
body: <p>In the old (pre .net core) era's entity framework 6 as shown in this <a href="https://romiller.com/2016/02/11/ef6-x-correlating-poor-performing-sql-to-application-code/" rel="noreferrer">blog post</a> there is a way to configure an interceptor which can log all slow queries including a stack backtrace.</p>
  
  <p>[ NOTE: In Entity Framework Core prior to version 3.0 this was not possible, thus the original question asked what to do instead.  Since the time this question was asked, new options and new versions of EF Core have been released. This question is historical now in nature, and some of the answers that were added later reference other newer versions of EF Core, where interceptors may have been reintroduced, to achieve feature parity with the pre-core era entity framework ]</p>
  
  <p>A question from 2015 about an earlier beta of what was then called EF7, suggests that it was not <a href="https://stackoverflow.com/questions/28526213/how-do-i-configure-an-entity-framework-interceptor-in-an-aspnet-vnext-config-jso">possible yet</a> in asp.net vnext early betas.</p>
  
  <p>Yet, the whole design of EF Core is to be composable, and in discussions on github bug tracker <a href="https://github.com/aspnet/EntityFramework/issues/1629" rel="noreferrer">here</a> that a technique might be possible where you subclass some low level class like <code>SqlServerConnection</code> and then override some method in there, to get some points you could hook before and after a query is executed, and add some low level logging if a millisecond timer value was executed.</p>
  
  <p>(Edit: References to pre-release information from 2015 removed in 2020)</p>