/

Console Output Configuration

Console output displays logs directly in your application's console. Configure console logging and caller information to enhance your debugging and development experience.

Enable Console Output

Enable console logging in LogSettings:

Log.Initialize(new LogSettings
{
    ConsoleEnabled = true  // Enable console output (default: false)
});

Caller Information

Include method, file, and line number information in logs:

Log.Initialize(new LogSettings
{
    ConsoleEnabled = true,
    IncludeCallerInfo = true  // Include caller info (default: true)
});

Caller Info Output Format

When IncludeCallerInfo is enabled, logs include:

[Info] [MyMethod:Program.cs:45] Application started successfully
[Error] [ProcessOrder:OrderService.cs:123] Failed to process order: Invalid data

Configuration Examples

Development Configuration

Log.Initialize(new LogSettings
{
    ConsoleEnabled = true,       // Show logs in console
    IncludeCallerInfo = true,    // Include detailed caller info
    MinimumLevel = LogLevel.Debug // Verbose console output
});

Production Configuration

Log.Initialize(new LogSettings
{
    ConsoleEnabled = false,      // Disable console in production
    IncludeCallerInfo = false,   // Reduce overhead
    MinimumLevel = LogLevel.Warn // Only important messages
});

Debugging Configuration

Log.Initialize(new LogSettings
{
    ConsoleEnabled = true,       // Enable for debugging
    IncludeCallerInfo = true,    // Full caller details
    MinimumLevel = LogLevel.Trace // All messages
});

Environment-Based Configuration

Automatic Environment Detection

var isDevelopment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development";

Log.Initialize(new LogSettings
{
    ConsoleEnabled = isDevelopment,      // Console only in development
    IncludeCallerInfo = isDevelopment    // Caller info only in development
});

Manual Environment Configuration

#if DEBUG
Log.Initialize(new LogSettings
{
    ConsoleEnabled = true,
    IncludeCallerInfo = true
});
#else
Log.Initialize(new LogSettings
{
    ConsoleEnabled = false,
    IncludeCallerInfo = false
});
#endif

Console Output Examples

With Caller Information

Log.Initialize(new LogSettings
{
    ConsoleEnabled = true,
    IncludeCallerInfo = true
});

Log.Info("User logged in");
// Output: [Info] [Login:AuthController.cs:67] User logged in

Without Caller Information

Log.Initialize(new LogSettings
{
    ConsoleEnabled = true,
    IncludeCallerInfo = false
});

Log.Info("User logged in");
// Output: [Info] User logged in

Console Colors

ByteHide Logger uses colored output based on log levels:

LevelColorConsole Display
TraceWhiteStandard text
DebugBlueBlue text
InfoGreenGreen text
WarnYellowYellow text
ErrorRedRed text
CriticalDark RedDark red text

Performance Considerations

Console Output Impact

SettingPerformance ImpactUse Case
ConsoleEnabled = trueModerate overheadDevelopment/debugging
ConsoleEnabled = falseNo overheadProduction
IncludeCallerInfo = trueHigher overheadDevelopment only
IncludeCallerInfo = falseLower overheadProduction

Optimization for Production

Log.Initialize(new LogSettings
{
    ConsoleEnabled = false,      // Disable console for performance
    IncludeCallerInfo = false,   // Reduce caller info overhead
    Persist = true,              // Use file logging instead
    FilePath = "logs/production.log"
});

Best Practices

Console Output Best Practices

  • Enable console output only in development environments
  • Use caller information for debugging but disable in production
  • Consider performance impact of console output in high-throughput applications
  • Combine with file logging for comprehensive logging strategy

Troubleshooting

Common Issues

IssueSolution
No console outputVerify ConsoleEnabled = true
Missing caller infoCheck IncludeCallerInfo = true
Performance issuesDisable console output in production
Colors not showingEnsure console supports ANSI colors
Previous
File Logging