Menu

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.

Note: Proper logging configuration is essential for monitoring, troubleshooting, and auditing your ApiCharge service.

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:

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:

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:

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:

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: