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:
C#
Log.Initialize(new LogSettings
{
ConsoleEnabled = true // Enable console output (default: false)
});Log.Initialize(new LogSettings
{
ConsoleEnabled = true // Enable console output (default: false)
});Caller Information
Include method, file, and line number information in logs:
C#
Log.Initialize(new LogSettings
{
ConsoleEnabled = true,
IncludeCallerInfo = true // Include caller info (default: true)
});Log.Initialize(new LogSettings
{
ConsoleEnabled = true,
IncludeCallerInfo = true // Include caller info (default: true)
});Caller Info Output Format
When IncludeCallerInfo is enabled, logs include:
CODE
[Info] [MyMethod:Program.cs:45] Application started successfully
[Error] [ProcessOrder:OrderService.cs:123] Failed to process order: Invalid data[Info] [MyMethod:Program.cs:45] Application started successfully
[Error] [ProcessOrder:OrderService.cs:123] Failed to process order: Invalid dataConfiguration Examples
Development Configuration
C#
Log.Initialize(new LogSettings
{
ConsoleEnabled = true, // Show logs in console
IncludeCallerInfo = true, // Include detailed caller info
MinimumLevel = LogLevel.Debug // Verbose console output
});Log.Initialize(new LogSettings
{
ConsoleEnabled = true, // Show logs in console
IncludeCallerInfo = true, // Include detailed caller info
MinimumLevel = LogLevel.Debug // Verbose console output
});Production Configuration
C#
Log.Initialize(new LogSettings
{
ConsoleEnabled = false, // Disable console in production
IncludeCallerInfo = false, // Reduce overhead
MinimumLevel = LogLevel.Warn // Only important messages
});Log.Initialize(new LogSettings
{
ConsoleEnabled = false, // Disable console in production
IncludeCallerInfo = false, // Reduce overhead
MinimumLevel = LogLevel.Warn // Only important messages
});Debugging Configuration
C#
Log.Initialize(new LogSettings
{
ConsoleEnabled = true, // Enable for debugging
IncludeCallerInfo = true, // Full caller details
MinimumLevel = LogLevel.Trace // All messages
});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
C#
var isDevelopment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development";
Log.Initialize(new LogSettings
{
ConsoleEnabled = isDevelopment, // Console only in development
IncludeCallerInfo = isDevelopment // Caller info only in development
});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
C#
#if DEBUG
Log.Initialize(new LogSettings
{
ConsoleEnabled = true,
IncludeCallerInfo = true
});
#else
Log.Initialize(new LogSettings
{
ConsoleEnabled = false,
IncludeCallerInfo = false
});
#endif#if DEBUG
Log.Initialize(new LogSettings
{
ConsoleEnabled = true,
IncludeCallerInfo = true
});
#else
Log.Initialize(new LogSettings
{
ConsoleEnabled = false,
IncludeCallerInfo = false
});
#endifConsole Output Examples
With Caller Information
C#
Log.Initialize(new LogSettings
{
ConsoleEnabled = true,
IncludeCallerInfo = true
});
Log.Info("User logged in");
// Output: [Info] [Login:AuthController.cs:67] User logged inLog.Initialize(new LogSettings
{
ConsoleEnabled = true,
IncludeCallerInfo = true
});
Log.Info("User logged in");
// Output: [Info] [Login:AuthController.cs:67] User logged inWithout Caller Information
C#
Log.Initialize(new LogSettings
{
ConsoleEnabled = true,
IncludeCallerInfo = false
});
Log.Info("User logged in");
// Output: [Info] User logged inLog.Initialize(new LogSettings
{
ConsoleEnabled = true,
IncludeCallerInfo = false
});
Log.Info("User logged in");
// Output: [Info] User logged inConsole 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
C#
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"
});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 |