Logging
The BookWorm application implements comprehensive logging using .NET's built-in logging framework enhanced with custom extensions and structured logging capabilities.
Logging Architecture
Framework Integration
- Microsoft.Extensions.Logging - Core logging abstraction
- Microsoft.Extensions.Compliance.Redaction - Sensitive data redaction
- Custom Logging Extensions - Enhanced logging capabilities in BookWorm.Chassis
Key Features
Structured Logging
- JSON-formatted log entries for better searchability and parsing
- Consistent log structure across all microservices
- Contextual information including correlation IDs and user context
Log Levels
- Trace - Detailed execution flow for debugging
- Debug - Development-time diagnostic information
- Information - General application flow and business events
- Warning - Potentially harmful situations that don't stop execution
- Error - Error events that allow the application to continue
- Critical - Serious errors that may cause application termination
Sensitive Data Protection
- Automatic redaction of personally identifiable information (PII)
- Configurable redaction patterns for different data types
- Compliance with data protection regulations (GDPR, CCPA)
Integration with OpenTelemetry
Trace Correlation
- Automatic correlation between logs and distributed traces
- Span context injection for cross-service request tracking
- Activity-based logging for request lifecycle monitoring
Log Forwarding
- Integration with OpenTelemetry logging pipeline
- Export to external systems (Grafana, Elastic Stack, Azure Monitor)
- Centralized log aggregation for distributed system monitoring
Best Practices
Logging Guidelines
- Use structured logging with consistent property names
- Avoid logging sensitive information in production
- Include relevant context (user ID, correlation ID, operation)
- Use appropriate log levels based on event severity
- Implement log sampling for high-volume scenarios
Performance Considerations
- Asynchronous logging to prevent blocking operations
- Log level filtering based on environment configuration
- Efficient serialization of log objects
- Batching and buffering for high-throughput scenarios