/

Disable Logging Configuration

There are several ways to disable or reduce logging in ByteHide Logger, from complete shutdown to selective filtering. Choose the method that best fits your needs.

Complete Logging Disable

Use the built-in disable method to stop all logging:

// Initialize logger normally
Log.Initialize(new LogSettings
{
    MinimumLevel = LogLevel.Info,
    ConsoleEnabled = true
});

// Disable logging completely
Log.Disable();

// All logging calls will be ignored
Log.Info("This will not be logged");
Log.Error("This will also be ignored");

// Re-enable logging when needed
Log.Enable();
Log.Info("This will be logged again");

Method 2: Don't Initialize Logger

The simplest way to disable logging is to not initialize the logger:

// Don't call Log.Initialize() at all
// Log.Initialize(new LogSettings { ... }); // Commented out

// All logging calls will be ignored
Log.Info("This will not be logged");
Log.Error("This will also be ignored");

Method 3: Set Minimum Level to Highest

Log.Initialize(new LogSettings
{
    MinimumLevel = LogLevel.Critical  // Only critical messages
});

// These will be ignored
Log.Info("Ignored");
Log.Warn("Ignored");  
Log.Error("Ignored");

// Only this will be logged
Log.Critical("This will be logged");

Conditional Disabling

Environment-Based Disabling

var isProduction = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Production";
var isHighTraffic = Environment.GetEnvironmentVariable("HIGH_TRAFFIC_MODE") == "true";

if (!isProduction || isHighTraffic)
{
    // Don't initialize logger in production or high-traffic scenarios
    return;
}

Log.Initialize(new LogSettings
{
    MinimumLevel = LogLevel.Warn
});

Feature Flag Disabling

public static class LoggerConfig
{
    public static void DisableLogging()
    {
        Log.Disable();
    }
    
    public static void EnableLogging()
    {
        Log.Enable();
    }
    
    public static void InitializeWithFeatureFlag(bool loggingEnabled)
    {
        Log.Initialize(new LogSettings
        {
            MinimumLevel = LogLevel.Info
        });
        
        if (!loggingEnabled)
        {
            Log.Disable();
        }
    }
}

Selective Disabling

Disable Console Only

Log.Initialize(new LogSettings
{
    ConsoleEnabled = false,    // Disable console output
    Persist = true,           // Keep file logging
    FilePath = "logs/app.log"
});

Disable File Logging Only

Log.Initialize(new LogSettings
{
    Persist = false,          // Disable file logging
    ConsoleEnabled = true     // Keep console output
});

Disable Cloud Logging Only

Log.Initialize(new LogSettings
{
    // Configure local logging
    Persist = true,
    ConsoleEnabled = true
});

// Don't set project token - logs stay local only
// Log.SetProjectToken("token"); // Commented out

Performance-Based Disabling

High-Traffic Configuration

Log.Initialize(new LogSettings
{
    MinimumLevel = LogLevel.Error,        // Only errors
    ConsoleEnabled = false,               // No console overhead
    IncludeCallerInfo = false,           // No caller info overhead
    DuplicateSuppressionWindow = TimeSpan.FromMinutes(5) // Aggressive suppression
});

Minimal Logging Configuration

Log.Initialize(new LogSettings
{
    MinimumLevel = LogLevel.Critical,     // Only critical messages
    ConsoleEnabled = false,
    IncludeCallerInfo = false,
    Persist = true,
    FilePath = "logs/critical-only.log"
});

Runtime Disabling

Using Built-in Enable/Disable Methods

public static class RuntimeLogControl
{
    public static void DisableAllLogging()
    {
        // Use built-in disable method
        Log.Disable();
    }
    
    public static void EnableLogging()
    {
        // Use built-in enable method
        Log.Enable();
    }
    
    public static void ToggleLogging(bool enabled)
    {
        if (enabled)
            Log.Enable();
        else
            Log.Disable();
    }
}

Dynamic Level Adjustment

public static class RuntimeLogControl
{
    public static void EnableErrorsOnly()
    {
        Log.Enable(); // Ensure logging is enabled first
        Log.Initialize(new LogSettings
        {
            MinimumLevel = LogLevel.Error
        });
    }
    
    public static void EnableFullLogging()
    {
        Log.Enable(); // Ensure logging is enabled first
        Log.Initialize(new LogSettings
        {
            MinimumLevel = LogLevel.Debug,
            ConsoleEnabled = true,
            Persist = true
        });
    }
}

Configuration Examples

Development - Full Logging

#if DEBUG
Log.Initialize(new LogSettings
{
    MinimumLevel = LogLevel.Debug,
    ConsoleEnabled = true,
    IncludeCallerInfo = true,
    Persist = true
});
#endif

Production - Minimal Logging

#if !DEBUG
Log.Initialize(new LogSettings
{
    MinimumLevel = LogLevel.Error,    // Errors only
    ConsoleEnabled = false,           // No console
    IncludeCallerInfo = false,       // No caller info
    Persist = true,
    FilePath = "logs/errors-only.log"
});
#endif

Testing - Disabled Logging

public class TestConfiguration
{
    public static void DisableLoggingForTests()
    {
        // Don't initialize logger during tests
        // This prevents log files from being created during test runs
    }
    
    public static void EnableTestLogging()
    {
        Log.Initialize(new LogSettings
        {
            MinimumLevel = LogLevel.Error,  // Only test errors
            ConsoleEnabled = true,          // Show in test output
            Persist = false                 // Don't create files
        });
    }
}

Environment Variable Control

Complete Disable via Environment

# Set environment variable to disable logging
BYTEHIDE_LOGGING_DISABLED=true
public static void InitializeWithEnvironmentControl()
{
    var loggingDisabled = Environment.GetEnvironmentVariable("BYTEHIDE_LOGGING_DISABLED") == "true";
    
    if (loggingDisabled)
    {
        // Don't initialize logger
        return;
    }
    
    Log.Initialize(new LogSettings
    {
        MinimumLevel = LogLevel.Info
    });
}

Level Control via Environment

# Set to disable most logging
BYTEHIDE_LOG_LEVEL=Critical
var logLevel = Environment.GetEnvironmentVariable("BYTEHIDE_LOG_LEVEL") ?? "Warn";
var level = Enum.Parse<LogLevel>(logLevel);

Log.Initialize(new LogSettings
{
    MinimumLevel = level
});

Best Practices

Disabling Logging Best Practices

  • Use environment variables for flexible logging control
  • Consider performance impact when choosing disable methods
  • Keep critical error logging even in high-performance scenarios
  • Test logging disable/enable in your deployment pipeline
  • Document logging configuration for your operations team

Verification

Check if Logging is Active

public static class LoggingStatus
{
    public static void TestLoggingStatus()
    {
        // Test with different methods
        Log.Info("Testing if logging is active");
        
        // Disable and test
        Log.Disable();
        Log.Info("This should not appear");
        
        // Re-enable and test
        Log.Enable();
        Log.Info("Logging re-enabled successfully");
    }
    
    public static void ReportLoggingMethods()
    {
        Console.WriteLine("Available logging control methods:");
        Console.WriteLine("- Log.Enable()  - Enables logging");
        Console.WriteLine("- Log.Disable() - Disables logging");
    }
}
Previous
Environment Variables