Unified Observability Stack with .NET ILogger, Elastic, and Sentry
Goal
Route logs from ILogger<T> to multiple sinks (Console, Elasticsearch, Sentry, Elastic APM) for comprehensive observability across development and production environments.
Unified Logging Interface
ILogger<T> routes logs to all configured sinks based on log levels, filters, and environment:
_logger.LogWarning("Something might be wrong here");
This single call outputs to:
- Console (dev environments)
- Elasticsearch (structured, queryable)
- Sentry (errors meeting severity threshold)
Sink Configuration
| Sink | Captures | Triggered By | Key Value |
|---|---|---|---|
| Console | Logs | All levels (e.g., dev only) | Local development visibility |
| Elastic (logs) | Logs (structured) | All log levels based on config | Centralized search and dashboards |
| Sentry | Exceptions and errors | Exceptions, logged or unhandled | Error visibility with stack traces |
| Elastic APM | Traces, spans, errors | Auto and manual instrumentation | Performance insights and bottlenecks |
Sink Responsibilities
Console: Real-time dev feedback, no persistence.
Elastic (logs): Persistent structured logs with trace ID correlation for trend analysis and postmortems.
Sentry: Actionable error capture with stack traces, breadcrumbs, and user context.
Elastic APM: Request flow traces identifying slow queries and external API calls, enriching logs with trace IDs.
Error Flow Example
Database exception occurs:
ILogger.LogError(...)called- Log distributed to:
- Console (dev)
- Elastic logs (structured + trace ID)
- Sentry (if severity threshold met)
- Elastic APM auto-captures:
- Full request trace
- DB call span
- Exception details
- Connected observability:
- Kibana log entry links to APM trace ID
- Sentry alert shows stack trace
- Prometheus
/metricsshows error spike
Observability Lens
| Tool | Main Focus | Data Type |
|---|---|---|
| Console | Local dev logs | Text |
| Elastic | Centralized logs | Structured JSON |
| Sentry | Error debugging | Exceptions + context |
| Elastic APM | Performance tracing | Spans + metrics |
Complete feedback loop: Detect (Metrics/APM) → Understand (Logs/Traces) → Fix (Sentry/Logs)