Log Levels Configuration
Log levels control which messages are processed and logged. Set the minimum level to filter out less important messages and optimize performance.
Available Log Levels
ByteHide Logger supports six log levels in order of severity:
Level | Type | Color | Use Case |
---|---|---|---|
LogLevel.Trace | Low | White | Most detailed diagnostic information |
LogLevel.Debug | Low | Blue | Detailed diagnostic information |
LogLevel.Info | Low | Green | General information messages |
LogLevel.Warn | Medium | Yellow | Warning messages for potential issues |
LogLevel.Error | High | Red | Error messages for failures |
LogLevel.Critical | Critical | Dark Red | Critical errors that may cause termination |
Setting Minimum Log Level
Configure the minimum level in LogSettings
:
Log.Initialize(new LogSettings
{
MinimumLevel = LogLevel.Info // Default: LogLevel.Warn
});
Level Filtering Behavior
When you set a minimum level, only messages at that level or higher are processed:
// Set minimum level to Info
Log.Initialize(new LogSettings { MinimumLevel = LogLevel.Info });
Log.Trace("This will be ignored"); // ❌ Below minimum
Log.Debug("This will be ignored"); // ❌ Below minimum
Log.Info("This will be logged"); // ✅ At minimum level
Log.Warn("This will be logged"); // ✅ Above minimum
Log.Error("This will be logged"); // ✅ Above minimum
Log.Critical("This will be logged"); // ✅ Above minimum
Environment-Specific Configuration
Development Environment
#if DEBUG
Log.Initialize(new LogSettings
{
MinimumLevel = LogLevel.Debug // Verbose logging for debugging
});
#endif
Production Environment
#if !DEBUG
Log.Initialize(new LogSettings
{
MinimumLevel = LogLevel.Warn // Only warnings and errors
});
#endif
Dynamic Configuration
var isDevelopment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development";
Log.Initialize(new LogSettings
{
MinimumLevel = isDevelopment ? LogLevel.Debug : LogLevel.Error
});
Usage Examples
Trace Level
Log.Trace("Entering method ProcessOrder with orderId: {OrderId}", orderId);
Debug Level
Log.Debug("Database query executed in {Duration}ms", stopwatch.ElapsedMilliseconds);
Info Level
Log.Info("User {UserId} logged in successfully", userId);
Warn Level
Log.Warn("API rate limit approaching: {CurrentCount}/{MaxCount}", current, max);
Error Level
Log.Error("Failed to process payment for order {OrderId}: {Error}", orderId, ex.Message);
Critical Level
Log.Critical("Database connection lost. Application shutting down.");
Performance Impact
Level | Performance | Use Case |
---|---|---|
Trace/Debug | Highest overhead | Development only |
Info | Moderate overhead | Development/staging |
Warn | Low overhead | Production (recommended) |
Error/Critical | Minimal overhead | High-performance production |
Best Practices
Level Selection Guidelines
- Development: Use
Debug
orInfo
for detailed diagnostics - Staging: Use
Info
orWarn
for testing scenarios - Production: Use
Warn
orError
for optimal performance - High-traffic: Use
Error
orCritical
for minimal overhead