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:
Level | Color | Console Display |
---|---|---|
Trace | White | Standard text |
Debug | Blue | Blue text |
Info | Green | Green text |
Warn | Yellow | Yellow text |
Error | Red | Red text |
Critical | Dark Red | Dark red text |
Performance Considerations
Console Output Impact
Setting | Performance Impact | Use Case |
---|---|---|
ConsoleEnabled = true | Moderate overhead | Development/debugging |
ConsoleEnabled = false | No overhead | Production |
IncludeCallerInfo = true | Higher overhead | Development only |
IncludeCallerInfo = false | Lower overhead | Production |
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
Issue | Solution |
---|---|
No console output | Verify ConsoleEnabled = true |
Missing caller info | Check IncludeCallerInfo = true |
Performance issues | Disable console output in production |
Colors not showing | Ensure console supports ANSI colors |