Search for existing suggestions

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.

101 votes
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)

    We’ll send you updates on this idea

    toshihiro.nakamura shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    7 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...
      • Cesar commented  ·   ·  Flag as inappropriate

        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.

        Cheers

      • Dmitry commented  ·   ·  Flag as inappropriate

        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  ·   ·  Flag as inappropriate

        .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.

      • smithd98 commented  ·   ·  Flag as inappropriate

        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  ·   ·  Flag as inappropriate

        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.

      Feedback and Knowledge Base