Feature Request
Add support for conditionally enabling call stack enrichment based on log level to optimize performance in production environments.
Use Case
In production, we typically only need call stack information for warnings, errors, and critical events. Information and debug logs don't usually need this level of detail, and enabling it for all log levels impacts performance.
Proposed API
.Enrich.WithCallStack(config => config
.EnableForLevels(LogEventLevel.Warning, LogEventLevel.Error, LogEventLevel.Fatal)
.WithCallStackFormat(useExceptionLikeFormat: true))
Or alternatively:
.Enrich.WithCallStack(config => config
.EnableWhen(logEvent => logEvent.Level >= LogEventLevel.Warning))
Benefits
- Performance: Skip expensive stack trace capture for info/debug logs
- Resource usage: Reduce memory and CPU overhead in high-volume scenarios
- Flexibility: Different enrichment strategies per environment
Current Workaround
Using multiple logger configurations:
// Verbose logger with call stack
var errorLogger = new LoggerConfiguration()
.Filter.ByIncludingOnly(e => e.Level >= LogEventLevel.Warning)
.Enrich.WithCallStack()
.WriteTo.File("errors.log")
.CreateLogger();
// Fast logger without call stack
var infoLogger = new LoggerConfiguration()
.Filter.ByIncludingOnly(e => e.Level < LogEventLevel.Warning)
.WriteTo.Console()
.CreateLogger();
This works but is cumbersome and requires managing multiple loggers.
Priority
Medium-High - would significantly improve production performance while maintaining debugging capabilities where needed.
Feature Request
Add support for conditionally enabling call stack enrichment based on log level to optimize performance in production environments.
Use Case
In production, we typically only need call stack information for warnings, errors, and critical events. Information and debug logs don't usually need this level of detail, and enabling it for all log levels impacts performance.
Proposed API
Or alternatively:
Benefits
Current Workaround
Using multiple logger configurations:
This works but is cumbersome and requires managing multiple loggers.
Priority
Medium-High - would significantly improve production performance while maintaining debugging capabilities where needed.