Using Loupe with Entity Framework - Introduction
If you're using Entity Framework 6 or later for data access you'll want to add the Loupe Agent for Entity Framework which automatically records log entries and metrics for EF actions.
Every EF call records at least two things – a performance metric and a log statement at the start of execution. If the call throws an exception you’ll also get a message at the end with the result information (logged as a warning so it’ll show up as a Loupe Application Event).
The log message includes the SQL statement, parameter values, information on the transaction (so on a busy system you can see what statements were really part of the same transaction, even if there are multiple operations on the same thread concurrently) as well as the server and call stack that got you there. You can tune the agent to increase or decrease the amount of detail recorded in configuration or at runtime.
For more information, see Using Loupe with Entity Framework - Tracing Actions
The performance metric includes the SQL statement, execution duration, success or failure, and number of rows affected. Using this information, Loupe Desktop can identify the top queries by duration, frequency, or total execution time and categorize performance of the same query by different input parameters.
For more information, see Using Loupe with Entity Framework - Analyzing Performance.
Loupe highly compresses each log message, making it safe and easy to record details like the full SQL statement of every database action without affecting your application's performance
You only need to add the Loupe Agent for Entity Framework to a single project in your solution. We recommend that you add it to the same project that contains your EF access code since it will already have a reference to EF. The Agent is available on NuGet - just add the package Gibraltar.Agent.EntityFramework. This will automatically add the core Loupe Agent if you haven't already.
To activate the agent you need to make one call to register it with Entity Framework. The call can be made multiple times safely (and without causing a double registration). Once registered with Entity Framework it will automatically record information for every EF 6 context in the application domain.
//Register the Interceptor
Gibraltar.Agent.EntityFramework.LoupeCommandInterceptor.Register();