Tutorials ADO.NET Core Tutorial
Query Logging — Complete Guide
Query Logging — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of ADO.NET Core Tutorial on Toolliyo Academy.
On this page
ADO.NET Core Tutorial · Lesson 75 of 100
Query Logging
Foundations ✓ → SQL & safety ✓ → Production → Projects
Production · 3 — ASP.NET & enterprise · ~10 min · Module 8: Testing and Debugging
What is this?
Log command text (dev) and timings (prod) from ADO.NET wrappers — with redaction.
Why should you care?
ShopNest debugging needs the exact proc name that failed.
See it live — copy this example
Use a .NET console or API project with SQL Server LocalDB. Run dotnet run after pasting.
_logger.LogDebug("Executing {CommandType} {Command}", cmd.CommandType, cmd.CommandText);
var sw = Stopwatch.StartNew();
await cmd.ExecuteNonQueryAsync(ct);
_logger.LogInformation("Executed in {Ms}ms", sw.ElapsedMilliseconds);
What happened?
- Debug level for text in non-prod.
- Info timings in prod.
- Never log secrets.
Practice next
- Wrapper logs text+ms.
- Toggle via log level.
- Redact.
- Include RowsAffected.
- Skip noisy health SQL.
Remember
Dev: text. Prod: timings. Redact PII.
ShopNest command logger
Repo decorator logs timings.
Outcome: Slow usp_ visible in App Insights.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!