Easy way to log SQL statements
Currently this requires lots of ceremony setting up ILogger infrastructure as described in https://docs.microsoft.com/en-us/ef/core/miscellaneous/logging.
Reopening since this was originally completed for EF6 and is possible but not easy in Entity Framework Core.
I support the last comment. It was very useful to determine what improvements could be done in the application.
I used Log property in LinQ to SQL and I'm getting crazy to find an "easy" and clean way to customize the logging.
Damian Powell commented
LINQ to SQL's "Log" field was very useful and simple to use. Please bring it to EF.
Just add named TraceSource to framework code and publish its name. Please. It's not very hard.
Just like Jaroslaw Kowalsky did in his EFOracleProvider. Simply sent qury string to the Trace. And we'll be able to catch it if we need it.
Ladislav Mrnka commented
.NET framework has big support for tracing so I cannot understand how could such elementary feature be omitted. ADO.NET team should really check how their colleagues in other teams preparing their API. Especially they should talk with WCF team where logging and extensibility was taken seriously.
EF should provide this through a config setting so it can be turned on to see what is happening for a slow query on prod.
Jon Miller commented
Do you mean an easy way to log the SQL that's generated by EF so that you can see what's going on behind the scenes? If so, I agree. It would been nice if you had elaborated a bit more on what it is that you're asking for. If you are using SQL Server, you can use SQL Profiler to see what's going on. But, I still think there should be a simple way to do this within EF itself in case you are using a server other than SQL Server. i.e. There should be a DBMS independent way to do this and you shouldn't have to rely on an additional tool. IMHO, EF should use System.Diagnostics logging and you should be able to configure the logging in App.config.
I think it is very important feature. It is now possible to implement logging via custom provider
But I think framework itself should provide such a feature.