Home > OS >  Logging SQL in Entity Framework Core
Logging SQL in Entity Framework Core

Time:01-24

I am attempting to log SQL statements in Entity Framework Core version 6.0.1, however when I attempt the following, I do not get access to the Log property in Visual Studio 2022 autocomplete, and I get a compilation error in my code if I write it manually:

using (var context = new BlogContext())
{
    context.Database.Log = Console.Write;
}

I am using version 6.0.x as the documentation indicates is required to use this feature:

enter image description here

What has me really confused is that if I look at the DatabaseFacade class documentation, which Visual Studio indicates is the type of the Database property, I cannot find the Log property.

Can anyone explain what I'm doing wrong?

CodePudding user response:

Please read this article in microsoft docs: https://docs.microsoft.com/en-us/ef/core/logging-events-diagnostics/simple-logging

  •  Tags:  
  • Related