Tutorials ADO.NET Core Tutorial
Logging — Complete Guide
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 38 of 100
Logging
Foundations ✓ → SQL & safety → Production → Projects
SQL & safety · 2 — Procs, tx, performance · ~6 min · Module 4: Transactions and Error Handling
What is this?
Log SQL timing, procedure names, and outcomes — never passwords or full card numbers.
Why should you care?
ShopNest incidents need “which query was slow” in seconds.
See it live — copy this example
Use a .NET console or API project with SQL Server LocalDB. Run dotnet run after pasting.
var sw = System.Diagnostics.Stopwatch.StartNew();
try { await cmd.ExecuteNonQueryAsync(ct); }
finally {
sw.Stop();
Console.WriteLine($"sql {cmd.CommandText} ms={sw.ElapsedMilliseconds}");
}
What happened?
- Structured logs with request id.
- Parameter values only in dev.
- Sample in production if volume is high.
Practice next
- Log duration.
- Include request id.
- Redact secrets.
- Log CommandType + proc name.
- Skip logging SELECT of blobs.
Remember
Time SQL calls. Correlate request id. Redact PII.
ShopNest SQL timing logs
Repos logs ms per command.
Outcome: Slow usp_ found quickly.
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!