Skip to main content

Logging Configuration Guide

This document provides instructions for configuring logging in Application using Serilog via a SerilogConfig.json file embedded with the application build.


Overview​

  • Application uses Serilog for structured logging.
  • Logging targets (called sinks) and log levels are configured via SerilogConfig.json.
  • The application is configured to support dynamic config reload for log levels at runtime when SerilogConfig.json is updated.
  • Changing log targets (WriteTo section) still requires an application restart.

Note
The logging configuration and guidance described in this document apply to both Azure deployments and on-premises deployments of the application. Configuration steps, log targets, and runtime log level changes are supported in both environments.


πŸ“‚ Configuration File Location​

The logging configuration is controlled through a SerilogConfig.json file placed within your application's build directory. Logs are in compact JSON format.


πŸ“ Available Logging Targets & Configuration Examples​

βœ… Console & File Logs​

{
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"Enrich": [ "FromLogContext", "WithThreadId" ],
"MinimumLevel": {
"Default": "Error",
"Override": {
"Microsoft": "Error",
"System": "Error"
}
},
"WriteTo": [
{
"Name": "Console",
"Args": {
"formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact"
}
},
{
"Name": "File",
"Args": {
"path": "%LOG_DIR%/Log/log.json",
"shared": true,
"fileSizeLimitBytes": 26214400,
"rollingInterval": "Infinite",
"rollOnFileSizeLimit": true,
"retainedFileCountLimit": 10,
"retainedFileTimeLimit": null,
"formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact"
}
}
]
}
}

Note:

  • The application sets the %LOG_DIR% variable at runtime to ensure log files are written to the application’s base directory:

βœ… Graylog Logs​

{
"Serilog": {
"Using": [ "Serilog.Sinks.Graylog" ],
"Enrich": [ "FromLogContext", "WithThreadId" ],
"MinimumLevel": {
"Default": "Error",
"Override": {
"Microsoft": "Error",
"System": "Error"
}
},
"WriteTo": [
{
"Name": "Graylog",
"Args": {
"HostnameOrAddress": "http://localhost",
"Port": 12201,
"TransportType": "Udp",
"UseSsl": false,
"formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact"
}
}
]
}
}

βš™οΈ Update HostnameOrAddress, Port, TransportType, and UseSsl as per your Graylog server setup.


βœ… Application Insights Logs​

{
"Serilog": {
"Using": [ "Serilog.Sinks.ApplicationInsights" ],
"Enrich": [ "FromLogContext", "WithThreadId" ],
"MinimumLevel": {
"Default": "Error",
"Override": {
"Microsoft": "Error",
"System": "Error"
}
},
"WriteTo": [
{
"Name": "ApplicationInsights",
"Args": {
"connectionString": "%ProtrakApplicationInsightsConnectionString%",
"telemetryConverter": "Serilog.Sinks.ApplicationInsights.TelemetryConverters.TraceTelemetryConverter, Serilog.Sinks.ApplicationInsights"
}
}
]
}
}

βš™οΈ Ensure %ProtrakApplicationInsightsConnectionString% is set as an environment variable on the host machine or environment.


πŸ”„ Changing Log Level at Runtime​

Application supports dynamically updating log levels at runtime via SerilogConfig.json without requiring a restart.

πŸ“Œ To Update Log Level:​

  • Open your SerilogConfig.json file.
  • Modify the MinimumLevel section like this:
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
}
  • The application automatically detects changes in SerilogConfig.json and applies the new log levels on the fly.

πŸ“Œ Supported Log Levels (Case-Insensitive)​

When setting log levels via configuration or runtime input, the following mappings apply:

Input ValueResolved Log Level
trace, verbose, verbVerbose
information, infoInformation
debugDebug
warning, warnWarning
errorError
fatal, criticalFatal
(anything else)Warning (default fallback)

⚠️ Known Limitations​

  • Changing logging targets (sinks) like switching from Console to Graylog or adding a new sink requires an application restart.
  • Only log levels can be modified dynamically at runtime via the SerilogConfig.json due to how Serilog reloads configurations.
ActionSupported at Runtime?Notes
πŸ”„ Change Log Levelβœ…Automatically applied when SerilogConfig.json changes
βž•βž– Add/Remove/Change Log Targets❌Requires application restart to take effect
πŸ”„ Update Application Insights Connection String❌Needs restart to reload updated environment variable

πŸ“Œ Best Practices​

  • Always verify environment variables (%LOG_DIR%, %ProtrakApplicationInsightsConnectionString%) are correctly configured on your deployment environment.
  • When switching log targets (Console ↔ File ↔ Graylog ↔ Application Insights), update SerilogConfig.json and restart the application.
  • To modify verbosity (log levels) for troubleshooting, simply edit SerilogConfig.json β€” no restart needed.

πŸ“£ Important​

Use the following logging tables and practices for consistent observability:

  • Exceptions Table: Capture all error logs.
  • Traces Table: Capture diagnostic and trace logs.
  • Use customDimensions.correlationId to track requests across services.
  • Always filter on TenantId in multi-tenant environments.

πŸ“„ Conclusion​

Application offers flexible, externalized logging via Serilog.
While log levels can be updated at runtime, changing log destinations requires a restart for reliability and stability.