-
-
Notifications
You must be signed in to change notification settings - Fork 1
Observability and Debugging
LAP-CHRIS\chris edited this page Mar 10, 2026
·
2 revisions
Language: English | Português (Brasil)
When a SQL-focused test fails, DbSqlLikeMem gives you several ways to inspect what happened without immediately jumping to a real database server.
| Symptom | Best first signal |
|---|---|
| Wrong rows or wrong SQL path |
LastExecutionPlan or LastExecutionPlans
|
| Need a retained artifact for CI or issue tracking |
GetDebugTraceSnapshotJson() or GetLastDebugTraceSnapshotJson()
|
| Need to assert event order | RecordingDbConnectionInterceptor |
| Need readable live output |
LoggingDbConnectionInterceptor, TextWriterDbConnectionInterceptor, or ILoggerDbConnectionInterceptor
|
| Need hooks for existing telemetry |
DiagnosticListenerDbConnectionInterceptor or ActivitySourceDbConnectionInterceptor
|
- Use
LastExecutionPlanorLastExecutionPlanswhen you want a quick view of the executed test path. - Use
GetDebugTraceSnapshotText()orGetDebugTraceSnapshotJson()when you want retained traces for the whole batch. - Use
GetLastDebugTraceSnapshotText()orGetLastDebugTraceSnapshotJson()when you only need the most recent retained trace. - Use
RecordingDbConnectionInterceptorwhen you want an inspectable in-memory event log. - Use
LoggingDbConnectionInterceptor,TextWriterDbConnectionInterceptor, orILoggerDbConnectionInterceptorwhen you want normalized event output. - Use
DiagnosticListenerDbConnectionInterceptororActivitySourceDbConnectionInterceptorwhen you want runtime-native hooks. - Use MiniProfiler Integration when your team already profiles ADO.NET flows.
- Re-run the failing test with the same provider mock.
- Inspect
LastExecutionPlanorLastExecutionPlans. - Export the retained debug trace as text or JSON.
- Add recording or logging interception if the failure still needs more context.
- Attach the text or JSON artifact to the failing test output or issue.
using Dapper;
using var connection = new SqliteConnectionMock(new SqliteDbMock());
connection.Open();
connection.Query<int>("select 1").ToList();
var traceJson = connection.GetLastDebugTraceSnapshotJson();Use this when the failure is already reproducible and you only need to inspect what was executed.
using var connection = new SqliteConnectionMock(new SqliteDbMock())
.WithInterception(options =>
{
options.UseRecording();
options.UseLogging(Console.WriteLine);
});Use this when you want both a human-readable stream and a retained recording of the same scenario.
using var connection = new SqliteConnectionMock(new SqliteDbMock())
.WithInterception(options =>
{
options.DiagnosticListener = new DiagnosticListener("DbSqlLikeMem.Tests");
options.ActivitySource = new ActivitySource("DbSqlLikeMem.Tests");
});Use this when your host already consumes DiagnosticListener or ActivitySource events.
- Start with retained traces before adding more wrappers.
- Add
RecordingDbConnectionInterceptorwhen you need assertions over the event stream. - Add human-readable logging only in tests or fixtures where it adds debugging value.
- Keep production-performance analysis on the real provider.
- Home
- Getting Started
- DotNet Fiddle Quick Start
- Provider Selection
- Providers and Compatibility
- ADO.NET and Dapper
- DbConnection Interception
- DI and Interception Setup
- Testing Strategy
- Diagnostics and Execution Plans
- Limitations and Known Gaps
- Recipes and Common Scenarios
- Transactions and Volatile Data
- Schema Snapshots and Replay
- FAQ and Troubleshooting
- Observability and Debugging
- Benchmark Results
- Provider-Specific Recipes
- Examples by Architecture
- Migration from Real DB Tests
- Performance of Test Suites
- Compatibility Matrix Summary
- Glossary
- Extensions and Ecosystem
- ORM and Test Integrations
- MiniProfiler Integration
- Visual Studio Extension
- VS Code Extension
- Maintainer Resources
- Início
- Começando
- Começando no .NET Fiddle
- Escolha do Provider
- Provedores e Compatibilidade
- ADO.NET e Dapper
- Interceptação de DbConnection
- Setup de DI e Interceptação
- Estratégia de Testes
- Diagnóstico e Planos de Execução
- Limitações e Gaps Conhecidos
- Receitas e Cenários Comuns
- Transações e Dados Voláteis
- Snapshots de Schema e Replay
- FAQ e Troubleshooting