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
Property | Type | Default Value | Description |
---|---|---|---|
Persist | bool | false | Enable/disable file logging |
FilePath | string | "logs.txt" | File path where logs are written |
RollingInterval | RollingInterval | Day | Interval for log file rotation |
RollOnFileSizeLimit | bool | true | Enable rotation when file reaches size limit |
FileSizeLimitBytes | long | 10485760 (10MB) | Maximum file size before rotation |
ConsoleEnabled | bool | false | Enable/disable console output |
IncludeCallerInfo | bool | true | Include method, file, and line number in logs |
MaskSensitiveData | string[] | ["password", "token"] | Property names to mask in logs |
DuplicateSuppressionWindow | TimeSpan? | null | Time window for suppressing duplicate messages |
MinimumLevel | LogLevel | LogLevel.Warn | Minimum 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 rotationRollingInterval.Minute
: Every minuteRollingInterval.Hour
: Every hourRollingInterval.Day
: Daily (recommended)RollingInterval.Week
: WeeklyRollingInterval.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 informationLogLevel.Debug
: Detailed diagnostic informationLogLevel.Info
: General information messagesLogLevel.Warn
: Warning messages for potential issuesLogLevel.Error
: Error messages for failuresLogLevel.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:
- Data Masking patterns
- User Identification setup
- Correlation IDs tracking
- Duplicate Suppression strategies
Framework Integration: