-->

How can I efficiently support Entity Framework SQL

2019-05-08 03:47发布

问题:


We're using Entity Framework 4.0. When we encounter a problem in production, we'd like to be able to temporarily enable logging of all SQL statements. We don't have enough permissions on the production SQL Server to run SQL Profiler.

Is there a good logging option that (a) can be turned on and off via a config file setting, and (b) doesn't add significant overhead when it's turned off?

I've read about the Tracing and Caching Provider Wrappers for Entity Framework. This sounds good... but it's sample code and isn't officially supported. So I'm not sure if it would be appropriate for production. I also don't know if the wrapper would add too much overhead even when logging is turned off. Has anyone had good experiences with these wrappers?


Thanks for your help,
Richard

回答1:

The code sample has been released in a NuGet package. It's been slightly modified to tie into the built-in .NET tracing system (using a TraceSource instead of just file/console logging).

I've used it on a couple of different projects, and I've found it helpful. It can be enabled/disabled from app.config/web.config just like any other TraceSource.

I haven't had any performance issues, but I'm only using it in single-user scenarios.