/

Logger SDK Features

Feature overview

ByteHide Logger provides enterprise-grade logging capabilities with advanced features for security, performance, and observability.

Core Logging Features

Multi-Level Logging

Support for standard logging levels with intelligent filtering:

using Bytehide.Logger.Core;

// Different log levels
Log.Debug("Detailed diagnostic information");
Log.Info("General application flow");
Log.Warn("Potential issues or important notices");
Log.Error("Error conditions that need attention");

// With exceptions
try 
{
    // Some operation
}
catch (Exception ex)
{
    Log.Error("Operation failed", ex);
}

Structured Logging

Log structured data for better analysis and querying:

// Log with structured data
Log.Info("User login", new {
    UserId = "12345",
    Username = "john.doe",
    LoginTime = DateTime.UtcNow,
    IpAddress = "192.168.1.100",
    UserAgent = "Mozilla/5.0..."
});

// Log with custom properties
Log.WithContext("OrderId", "ORD-001")
   .WithContext("CustomerId", "CUST-456")
   .Info("Order processed successfully");

Security Features

Automatic Data Masking

Protect sensitive information automatically:

Log.Initialize(new LogSettings
{
    MaskSensitiveData = new[] { "password", "token", "secret", "key" }
});

// Sensitive data is automatically masked
Log.Info("User credentials", new {
    Username = "john.doe",
    Password = "secret123",  // Becomes "***"
    ApiToken = "abc123xyz"   // Becomes "***"
});

Custom Masking Rules

Define custom patterns for data masking:

Log.Initialize(new LogSettings
{
    MaskSensitiveData = new[] 
    { 
        "password", "token", "secret", "key",
        "credential", "connectionstring", "api_key",
        "bearer_token", "auth_header", "private_key"
    }
});

Performance Features

Duplicate Suppression

Prevent log flooding with intelligent duplicate detection:

Log.Initialize(new LogSettings
{
    DuplicateSuppressionWindow = TimeSpan.FromSeconds(5)
});

// Only the first occurrence will be logged within 5 seconds
for (int i = 0; i < 100; i++)
{
    Log.Warn("Database connection timeout"); // Logged once
}

Asynchronous Logging

Non-blocking logging for high-performance applications:

// Asynchronous logging methods
await Log.InfoAsync("Async operation completed");
await Log.ErrorAsync("Async operation failed", exception);

// Fire-and-forget logging (non-blocking)
Log.Info("High-frequency event"); // Returns immediately

Memory-Efficient Logging

Optimized for minimal memory allocation:

// Efficient string interpolation
Log.Info($"Processing order {orderId} for customer {customerId}");

// Lazy evaluation for expensive operations
Log.Debug(() => $"Complex calculation result: {ExpensiveCalculation()}");

Advanced Logging Features

Correlation IDs

Track requests across distributed systems:

// Set correlation ID for the current context
Log.SetCorrelationId("REQ-12345");

// All subsequent logs will include this correlation ID
Log.Info("Processing started");
Log.Info("Validation completed");
Log.Info("Processing finished");

// Clear correlation ID
Log.ClearCorrelationId();

User Identification

Associate logs with specific users:

using Bytehide.Logger.Common.Models.Users;

// Identify user for all subsequent logs
Log.Identify(new AuthUser 
{ 
    Id = "user-123", 
    Email = "john.doe@company.com",
    Name = "John Doe"
});

Log.Info("User action performed"); // Includes user context

// Clear user identification
Log.ClearIdentity();