/

Environment Variables Configuration

Environment variables provide a flexible way to configure ByteHide Logger across different environments without changing code. Ideal for containerized applications and CI/CD deployments.

Common Environment Variables

Project Token

# Set your ByteHide project token
BYTEHIDE_PROJECT_TOKEN=your-project-token-here
// Use in your application
var projectToken = Environment.GetEnvironmentVariable("BYTEHIDE_PROJECT_TOKEN");
Log.SetProjectToken(projectToken);

Log Level

# Set minimum log level
BYTEHIDE_LOG_LEVEL=Info
// Parse and use log level
var logLevelStr = Environment.GetEnvironmentVariable("BYTEHIDE_LOG_LEVEL") ?? "Warn";
var logLevel = Enum.Parse<LogLevel>(logLevelStr);

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

File Path

# Set log file path
BYTEHIDE_LOG_PATH=logs/application.log
// Use custom log path
var logPath = Environment.GetEnvironmentVariable("BYTEHIDE_LOG_PATH") ?? "logs.txt";

Log.Initialize(new LogSettings
{
    Persist = true,
    FilePath = logPath
});

Complete Environment Configuration

Environment Variables

# Core settings
BYTEHIDE_PROJECT_TOKEN=your-project-token
BYTEHIDE_LOG_LEVEL=Info
BYTEHIDE_LOG_PATH=logs/app.log

# Console settings
BYTEHIDE_CONSOLE_ENABLED=true
BYTEHIDE_CALLER_INFO=true

# File settings
BYTEHIDE_FILE_SIZE_MB=25
BYTEHIDE_ROLLING_INTERVAL=Day

# Performance settings
BYTEHIDE_DUPLICATE_SUPPRESSION_SECONDS=5

Application Configuration

public static class EnvironmentLoggerConfig
{
    public static void Initialize()
    {
        var settings = new LogSettings
        {
            // Core settings
            MinimumLevel = ParseLogLevel(Environment.GetEnvironmentVariable("BYTEHIDE_LOG_LEVEL")),
            
            // Console settings
            ConsoleEnabled = ParseBool(Environment.GetEnvironmentVariable("BYTEHIDE_CONSOLE_ENABLED")),
            IncludeCallerInfo = ParseBool(Environment.GetEnvironmentVariable("BYTEHIDE_CALLER_INFO")),
            
            // File settings
            Persist = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("BYTEHIDE_LOG_PATH")),
            FilePath = Environment.GetEnvironmentVariable("BYTEHIDE_LOG_PATH") ?? "logs.txt",
            FileSizeLimitBytes = ParseFileSizeMB(Environment.GetEnvironmentVariable("BYTEHIDE_FILE_SIZE_MB")),
            RollingInterval = ParseRollingInterval(Environment.GetEnvironmentVariable("BYTEHIDE_ROLLING_INTERVAL")),
            
            // Performance settings
            DuplicateSuppressionWindow = ParseDuplicateSuppressionSeconds(Environment.GetEnvironmentVariable("BYTEHIDE_DUPLICATE_SUPPRESSION_SECONDS"))
        };
        
        Log.Initialize(settings);
        
        // Set project token
        var projectToken = Environment.GetEnvironmentVariable("BYTEHIDE_PROJECT_TOKEN");
        if (!string.IsNullOrEmpty(projectToken))
        {
            Log.SetProjectToken(projectToken);
        }
    }
    
    private static LogLevel ParseLogLevel(string value)
    {
        return Enum.TryParse<LogLevel>(value, out var level) ? level : LogLevel.Warn;
    }
    
    private static bool ParseBool(string value)
    {
        return bool.TryParse(value, out var result) && result;
    }
    
    private static long ParseFileSizeMB(string value)
    {
        return int.TryParse(value, out var sizeMB) ? sizeMB * 1024 * 1024 : 10 * 1024 * 1024;
    }
    
    private static RollingInterval ParseRollingInterval(string value)
    {
        return value?.ToLower() switch
        {
            "none" => RollingInterval.None,
            "minute" => RollingInterval.Minute,
            "hour" => RollingInterval.Hour,
            "day" => RollingInterval.Day,
            "week" => RollingInterval.Week,
            "month" => RollingInterval.Month,
            _ => RollingInterval.Day
        };
    }
    
    private static TimeSpan? ParseDuplicateSuppressionSeconds(string value)
    {
        return int.TryParse(value, out var seconds) ? TimeSpan.FromSeconds(seconds) : null;
    }
}

Docker Configuration

Dockerfile

# Set default environment variables
ENV BYTEHIDE_LOG_LEVEL=Warn
ENV BYTEHIDE_CONSOLE_ENABLED=false
ENV BYTEHIDE_LOG_PATH=logs/production.log
ENV BYTEHIDE_FILE_SIZE_MB=50

Docker Compose

version: '3.8'
services:
  myapp:
    image: myapp:latest
    environment:
      - BYTEHIDE_PROJECT_TOKEN=${BYTEHIDE_PROJECT_TOKEN}
      - BYTEHIDE_LOG_LEVEL=Info
      - BYTEHIDE_CONSOLE_ENABLED=false
      - BYTEHIDE_LOG_PATH=logs/app.log
      - BYTEHIDE_FILE_SIZE_MB=25
      - BYTEHIDE_ROLLING_INTERVAL=Day
    volumes:
      - ./logs:/app/logs

Kubernetes Configuration

ConfigMap

apiVersion: v1
kind: ConfigMap
metadata:
  name: bytehide-logger-config
data:
  BYTEHIDE_LOG_LEVEL: "Info"
  BYTEHIDE_CONSOLE_ENABLED: "false"
  BYTEHIDE_LOG_PATH: "logs/k8s-app.log"
  BYTEHIDE_FILE_SIZE_MB: "50"
  BYTEHIDE_ROLLING_INTERVAL: "Day"

Secret for Token

apiVersion: v1
kind: Secret
metadata:
  name: bytehide-secrets
type: Opaque
data:
  BYTEHIDE_PROJECT_TOKEN: <base64-encoded-token>

Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  template:
    spec:
      containers:
      - name: myapp
        image: myapp:latest
        envFrom:
        - configMapRef:
            name: bytehide-logger-config
        - secretRef:
            name: bytehide-secrets

Environment-Specific Examples

Development

export BYTEHIDE_LOG_LEVEL=Debug
export BYTEHIDE_CONSOLE_ENABLED=true
export BYTEHIDE_CALLER_INFO=true
export BYTEHIDE_LOG_PATH=logs/debug.log
export BYTEHIDE_FILE_SIZE_MB=5

Staging

export BYTEHIDE_PROJECT_TOKEN=staging-token-here
export BYTEHIDE_LOG_LEVEL=Info
export BYTEHIDE_CONSOLE_ENABLED=false
export BYTEHIDE_LOG_PATH=logs/staging.log
export BYTEHIDE_FILE_SIZE_MB=25

Production

export BYTEHIDE_PROJECT_TOKEN=production-token-here
export BYTEHIDE_LOG_LEVEL=Warn
export BYTEHIDE_CONSOLE_ENABLED=false
export BYTEHIDE_CALLER_INFO=false
export BYTEHIDE_LOG_PATH=logs/production.log
export BYTEHIDE_FILE_SIZE_MB=100
export BYTEHIDE_DUPLICATE_SUPPRESSION_SECONDS=10

Best Practices

Environment Variables Best Practices

  • Use descriptive prefixes (e.g., BYTEHIDE_) to avoid conflicts
  • Provide sensible defaults in your configuration parsing
  • Keep sensitive data in secrets (project tokens, credentials)
  • Document required variables for your deployment team
  • Validate environment variables at application startup

Validation Example

public static void ValidateEnvironmentConfiguration()
{
    var requiredVars = new[] { "BYTEHIDE_PROJECT_TOKEN" };
    var missingVars = requiredVars.Where(var => string.IsNullOrEmpty(Environment.GetEnvironmentVariable(var))).ToList();
    
    if (missingVars.Any())
    {
        throw new InvalidOperationException($"Missing required environment variables: {string.Join(", ", missingVars)}");
    }
    
    Log.Info("Environment configuration validated successfully");
}
Previous
Console Output