/

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:

LevelTypeColorUse Case
LogLevel.TraceLowWhiteMost detailed diagnostic information
LogLevel.DebugLowBlueDetailed diagnostic information
LogLevel.InfoLowGreenGeneral information messages
LogLevel.WarnMediumYellowWarning messages for potential issues
LogLevel.ErrorHighRedError messages for failures
LogLevel.CriticalCriticalDark RedCritical 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

LevelPerformanceUse Case
Trace/DebugHighest overheadDevelopment only
InfoModerate overheadDevelopment/staging
WarnLow overheadProduction (recommended)
Error/CriticalMinimal overheadHigh-performance production

Best Practices

Level Selection Guidelines

  • Development: Use Debug or Info for detailed diagnostics
  • Staging: Use Info or Warn for testing scenarios
  • Production: Use Warn or Error for optimal performance
  • High-traffic: Use Error or Critical for minimal overhead
Previous
Project Token