Logging

The logging API built into .NET Core should be used for most all scenarios.

Logging providers should be included at design time but configured at runtime using configuration (appsetting.json). Configuring logging at runtime will allow for different logging levels and logging destinations to be applied for each environment. For example, it is generally best practice NOT to log informational messages in production, but you may wish to log information messages in lower environments for troubleshooting and debugging.

Logging to the Azure Application Insights provider should be performed in all environments except when developing locally. By using Azure Application Insights, we will be able to centralize logging (and telemetry) across many applications in one place.

Logging to a database should be avoided.

Except when developing locally, applications should NOT log to a file or the local file system.

For more information about .NET Core Logging, visit https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/

Application Insights, a feature of Azure Monitor, is an extensible service for developers and DevOps professionals. It can be used to monitor your live applications. It will automatically detect performance anomalies, and includes powerful analytics tools to help you diagnose issues and to understand what users actually do with an app. It is designed to help continuously improve performance and usability.

Instead of logging errors to a database, developers should post custom errors to Application Insights for centralized reporting and greater analysis into the overall application state.

PREVIOUS: Configuration
Solution Architecture Guidance
NEXT: Dependency Injection