Search⌘ K
AI Features

Logging EF Core

Explore how to enable logging in Entity Framework Core to monitor database connections and commands. Learn to filter logs by event IDs and use query tags to simplify debugging complex LINQ queries. Understand best practices for including and excluding sensitive data in logs during development and production.

Logging

We can enable logging to monitor the interaction between EF Core and the database. Logging could be to the console, Debug or Trace, or a file.

EF Core logging

By default, EF Core logging will exclude any data in case it is sensitive. We can include this data by calling the EnableSensitiveDataLogging method, especially during development. We should disable it again before deploying it to production.

Example

Let’s see an example of this in action:

Step 1: ...