我可以的EntityFramework核心1.0 RC2配置拦截了吗? [英] Can I configure an interceptor yet in EntityFramework Core 1.0 rc2?
问题描述
在实体框架6如本的博客文章有配置它可以记录所有的查询速度慢,包括在堆栈中的拦截器的方法。
In entity framework 6 as shown in this blog post there is a way to configure an interceptor which can log all slow queries including a stack backtrace.
从2015年约一个问题的当时所谓EF7的早期测试,表明它不是的
A question from 2015 about an earlier beta of what was then called EF7, suggests that it was not possible yet in asp.net vnext early betas.
然而,EF核心的整体设计是为了>可能尚未可组合,并在GitHub上的bug跟踪讨论这里一种技术,有可能你在哪里继承一些低级别类如 SqlServerConnection
然后重写某些方法在那里,让你可以之前执行一个查询后钩一些分数,如果加上一些低级别的日志毫秒定时器的值被执行了。
Yet, the whole design of EF Core is to be composable, and in discussions on github bug tracker here that a technique might be possible where you subclass some low level class like SqlServerConnection
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.
是仍然有必要和EF核心的唯一方法1.0.0-RC2决赛(电流2016年6月)的?
Is that still necessary and the only technique in EF Core 1.0.0-rc2-final (current as of June 2016) ?
推荐答案
EF Core不具有拦截器或类似的生命周期挂钩呢。此功能在这里追踪: https://github.com/aspnet/EntityFramework/issues/626一>
EF Core does not have "interceptors" or similar lifecycle hooks yet. This feature is tracked here: https://github.com/aspnet/EntityFramework/issues/626.
覆盖低级别的组件可能是不必要的。许多低级别的EF核心组件已经产生日志,日志记录,包括查询执行。您可以配置EF通过调用 DbContextOptionsBuilder.UseLoggerFactory(ILoggerFactory厂)使用自定义记录器工厂
。 (请参见 https://docs.asp.net/en/latest/fundamentals/logging html的和 https://github.com/aspnet/Logging 以获取更多详细信息记录器界面)EF核心产生一些显着的日志事件具有良好定义事件ID。 (请参阅 Microsoft.EntityFrameworkCore.Infrastructure.CoreLoggingEventId
在1.0.0-RC2,它更名为刚 Microsoft.EntityFrameworkCore.Infrastructure.CoreEventId
为1.0.0 RTM)请参见的https://docs.efproject .NET / EN /最新/杂项/ logging.html 这样做的例子。
Overriding a low-level component may be unnecessary if all you want is log output. Many low-level EF Core components already produces logging, logging including query execution. You can configure EF to use a custom logger factory by calling DbContextOptionsBuilder.UseLoggerFactory(ILoggerFactory factory)
. (See https://docs.asp.net/en/latest/fundamentals/logging.html and https://github.com/aspnet/Logging for more details on this logger interface.) EF Core produces some notable log events with well-define event IDs. (See Microsoft.EntityFrameworkCore.Infrastructure.CoreLoggingEventId
in 1.0.0-rc2, which was renamed to justMicrosoft.EntityFrameworkCore.Infrastructure.CoreEventId
for 1.0.0 RTM.) See https://docs.efproject.net/en/latest/miscellaneous/logging.html for examples of doing this.
如果您需要更多的记录超出了EF核心组件已经产生,你需要重写EF核心的低层组件。这是最好的覆盖存在部分完成,通过依赖注入添加了此overridding版本EF。这样做需要配置自定义服务提供商EF内部使用。这是由配置DbContextOptionsBuilder.UseInternalServiceProvider(IServiceProvider的服务)
见的 https://docs.efproject.net/en/latest/miscellaneous/internals/services.html 关于EF如何使用服务内部的更多细节。
If you need additional logging beyond what EF Core components already produce, you will need to override EF Core's lower-level components. This is best done by overriding the exist component and added this overridding version to EF via dependency injection. Doing this requires configuring a custom service provider for EF to use internally. This is configured by DbContextOptionsBuilder.UseInternalServiceProvider(IServiceProvider services)
See https://docs.efproject.net/en/latest/miscellaneous/internals/services.html for more details on how EF uses services internally.
这篇关于我可以的EntityFramework核心1.0 RC2配置拦截了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!