Adding logging
It's sometimes important, namely when things go wrong, to get a glimpse of what's going on inside. For that, we can leverage the logging capabilities of Entity Framework Core: we are presented with a detailed register of what is happening, such as the SQL that is being sent to the database.
Getting ready
We will be using the NuGet Package Manager to install the Entity Framework Core 1 package, Microsoft.EntityFrameworkCore
. We will also be using a SQL Server database to store the data, so we will also need Microsoft.EntityFrameworkCore.SqlServer
.
We also need the Microsoft.Extensions.Logging
and Microsoft.Extensions.Logging.Console
packages to add logging capabilities.
Open Using EF Core Solution from the included source code examples.
Execute the database setup script from the code samples included for this recipe. This can be found in the DataAccess
project within the Database
folder.
How to do it…
Let's create a sample context and entity, add logging capabilities, and see what...