Logging Configuration
ApiCharge uses the standard .NET logging framework to capture information about the service's operations. This page explains how to configure logging for your ApiCharge deployment.
Basic Configuration
ApiCharge's logging configuration is defined in the Logging
section of your appsettings.json
file:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
This example configures:
- Default log level of
Information
for all categories - Log level of
Warning
for categories starting with "Microsoft.AspNetCore"
Log Levels
ApiCharge supports the following log levels, from least to most severe:
Level | Description | Example |
---|---|---|
Trace |
Highly detailed debugging information | Method entry/exit, variable values |
Debug |
Debugging information useful during development | Configuration values, intermediate results |
Information |
General application flow information | Request received, service started/stopped |
Warning |
Potential issues that don't prevent operation | Rate limiter approaching threshold, retrying operation |
Error |
Error conditions that affect operation | API request failed, database connection error |
Critical |
Critical failures requiring immediate attention | Service unavailable, security breach |
When you specify a log level, logging for that level and all higher levels is enabled. For example, if you set "Default": "Warning"
, logs at Warning, Error, and Critical levels will be captured.
Log Categories
ApiCharge uses the following log categories:
ApiChargePrototype
- General service logsApiChargePrototype.Api
- API endpoint logsApiChargePrototype.Middleware
- Middleware component logsApiChargePrototype.Entities
- Entity-related logsApiChargePrototype.Exceptions
- Exception and error handling logsMicrosoft.AspNetCore
- ASP.NET Core framework logs
You can configure different log levels for different categories:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"ApiChargePrototype.Middleware": "Debug"
}
}
}
Configuring Console Output Format
You can customize the console logging format by adding the Console
section to your logging configuration:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
},
"Console": {
"IncludeScopes": true,
"TimestampFormat": "yyyy-MM-dd HH:mm:ss "
}
}
}
This configuration:
- Enables logging scopes (logical grouping of log messages)
- Includes timestamps in the format "2025-01-01 14:30:45"
Environment-Specific Logging
You can define different logging configurations for different environments:
Development Environment (appsettings.Development.json)
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"Microsoft.AspNetCore": "Information"
}
}
}
Production Environment (appsettings.Production.json)
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
This approach allows more verbose logging during development while keeping production logs concise.
Performance Considerations
When configuring logging, keep these performance considerations in mind:
- Log Volume: Trace and Debug levels generate a high volume of logs, which can impact performance.
- Storage Requirements: High-volume logging requires more storage space.
- Log Rotation: Implement log rotation if using file-based logging to prevent filling disk space.
- Console Logging: Console logging can slow down applications in high-throughput scenarios.
For production environments, it's generally recommended to use Information level for default logging, with Warning or Error levels for framework components.
Additional Resources
For more information about .NET logging:
Next Steps
Learn more about ApiCharge configuration:
- Global Settings - Core service configuration
- Environment Variables - Security-sensitive settings
- Deployment Options - Different ways to deploy ApiCharge