/

Logger SDK Configuration

Configuration overview

ByteHide Logger is configured through the LogSettings class, which provides comprehensive options for logging behavior, file management, security, and performance optimization.

LogSettings Overview

The LogSettings class is the main configuration object for ByteHide Logger. Here's how to initialize it:

using Bytehide.Logger.Core;
using Bytehide.Logger.Common.Models;

Log.Initialize(new LogSettings
{
    // Configure your logging settings here
});

// Set your project token
Log.SetProjectToken("your-project-token");

Project Token Configuration

By simply adding your project token, all logs will be automatically sent to the ByteHide cloud platform without any additional configuration. If you don't set a project token, logs will only be stored in local files. For more information about obtaining and configuring your project token, see Project Token setup.

LogSettings Properties

PropertyTypeDefault ValueDescription
PersistboolfalseEnable/disable file logging
FilePathstring"logs.txt"File path where logs are written
RollingIntervalRollingIntervalDayInterval for log file rotation
RollOnFileSizeLimitbooltrueEnable rotation when file reaches size limit
FileSizeLimitByteslong10485760 (10MB)Maximum file size before rotation
ConsoleEnabledboolfalseEnable/disable console output
IncludeCallerInfobooltrueInclude method, file, and line number in logs
MaskSensitiveDatastring[]["password", "token"]Property names to mask in logs
DuplicateSuppressionWindowTimeSpan?nullTime window for suppressing duplicate messages
MinimumLevelLogLevelLogLevel.WarnMinimum log level to process

File Persistence Settings

Control how logs are saved to files:

Log.Initialize(new LogSettings
{
    // Enable/disable file logging
    Persist = true,                                    // Default: false
    
    // File path for log output
    FilePath = "logs/application.log",                 // Default: "logs.txt"
    
    // File rotation settings
    RollingInterval = RollingInterval.Day,             // Default: Day
    RollOnFileSizeLimit = true,                        // Default: true
    FileSizeLimitBytes = 10 * 1024 * 1024             // Default: 10MB
});

Available Rolling Intervals:

  • RollingInterval.None: No rotation
  • RollingInterval.Minute: Every minute
  • RollingInterval.Hour: Every hour
  • RollingInterval.Day: Daily (recommended)
  • RollingInterval.Week: Weekly
  • RollingInterval.Month: Monthly

Console Output Settings

Configure console logging:

Log.Initialize(new LogSettings
{
    ConsoleEnabled = true,          // Default: false
    IncludeCallerInfo = true        // Default: true (shows method, file, line)
});

Log Level Configuration

Set the minimum log level to process:

Log.Initialize(new LogSettings
{
    MinimumLevel = LogLevel.Info    // Default: LogLevel.Warn
});

Available Log Levels (in order of severity):

  • LogLevel.Trace: Most detailed diagnostic information
  • LogLevel.Debug: Detailed diagnostic information
  • LogLevel.Info: General information messages
  • LogLevel.Warn: Warning messages for potential issues
  • LogLevel.Error: Error messages for failures
  • LogLevel.Critical: Critical errors that may cause application termination

Security Settings

Configure data masking for sensitive information:

Log.Initialize(new LogSettings
{
    // Mask sensitive data in logs
    MaskSensitiveData = new[] { "password", "token", "secret", "key" }
    // Default: ["password", "token"]
});

Performance Settings

Configure duplicate suppression:

Log.Initialize(new LogSettings
{
    // Suppress duplicate messages within time window
    DuplicateSuppressionWindow = TimeSpan.FromSeconds(5)  // Default: null (disabled)
});

Configuration Examples

Development Environment

Log.Initialize(new LogSettings
{
    // Verbose logging for development
    MinimumLevel = LogLevel.Debug,
    ConsoleEnabled = true,
    IncludeCallerInfo = true,
    
    // File logging
    Persist = true,
    FilePath = "logs/debug.log",
    RollingInterval = RollingInterval.Hour,
    
    // Basic security
    MaskSensitiveData = new[] { "password", "token" }
});

Production Environment

Log.Initialize(new LogSettings
{
    // Production-level logging
    MinimumLevel = LogLevel.Warn,
    ConsoleEnabled = false,
    IncludeCallerInfo = false,
    
    // Robust file logging
    Persist = true,
    FilePath = "logs/production.log",
    RollingInterval = RollingInterval.Day,
    RollOnFileSizeLimit = true,
    FileSizeLimitBytes = 50 * 1024 * 1024,  // 50MB
    
    // Enhanced security
    MaskSensitiveData = new[] { 
        "password", "token", "secret", "key", 
        "credential", "connectionstring", "api_key" 
    },
    
    // Performance optimization
    DuplicateSuppressionWindow = TimeSpan.FromSeconds(10)
});

High-Performance Configuration

Log.Initialize(new LogSettings
{
    // Minimal logging for performance
    MinimumLevel = LogLevel.Error,
    ConsoleEnabled = false,
    IncludeCallerInfo = false,
    
    // Efficient file management
    Persist = true,
    FilePath = "logs/errors.log",
    RollingInterval = RollingInterval.Day,
    FileSizeLimitBytes = 100 * 1024 * 1024,  // 100MB
    
    // Aggressive duplicate suppression
    DuplicateSuppressionWindow = TimeSpan.FromMinutes(1),
    
    // Essential masking only
    MaskSensitiveData = new[] { "password", "token" }
});

Complete Configuration Example

Log.Initialize(new LogSettings
{
    // Basic settings
    MinimumLevel = LogLevel.Info,
    ConsoleEnabled = false,
    IncludeCallerInfo = true,
    
    // File persistence
    Persist = true,
    FilePath = "logs/application.log",
    RollingInterval = RollingInterval.Day,
    RollOnFileSizeLimit = true,
    FileSizeLimitBytes = 25 * 1024 * 1024,  // 25MB
    
    // Security
    MaskSensitiveData = new[] { 
        "password", "token", "secret", "key",
        "credential", "connectionstring", "api_key",
        "bearer_token", "auth_token"
    },
    
    // Performance
    DuplicateSuppressionWindow = TimeSpan.FromSeconds(5),
    
    // User context
    Auth = new AuthData
    {
        UserId = Environment.UserName,
        UserName = Environment.UserName
    }
});

// Set project token
Log.SetProjectToken("your-project-token");

Environment-Based Configuration

public static class LoggerConfig
{
    public static void Initialize()
    {
        var isDevelopment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development";
        
        var settings = new LogSettings
        {
            MinimumLevel = isDevelopment ? LogLevel.Debug : LogLevel.Warn,
            ConsoleEnabled = isDevelopment,
            IncludeCallerInfo = isDevelopment,
            
            Persist = true,
            FilePath = isDevelopment ? "logs/debug.log" : "logs/production.log",
            RollingInterval = RollingInterval.Day,
            FileSizeLimitBytes = isDevelopment ? 10 * 1024 * 1024 : 50 * 1024 * 1024,
            
            MaskSensitiveData = new[] { "password", "token", "secret" },
            DuplicateSuppressionWindow = isDevelopment ? null : TimeSpan.FromSeconds(10)
        };
        
        Log.Initialize(settings);
        Log.SetProjectToken(Environment.GetEnvironmentVariable("BYTEHIDE_PROJECT_TOKEN"));
    }
}

Next Steps

After configuring the basic settings, explore these advanced topics:

Configuration:

Features:

Framework Integration:

Previous
Installation