docs/en/solution-templates/single-layer-web-application/logging.md
//[doc-seo]
{
"Description": "Learn how to implement structured logging in ABP Framework using Serilog, with common configuration for easy integration."
}
//[doc-nav]
{
"Previous": {
"Name": "Database configurations",
"Path": "solution-templates/single-layer-web-application/database-configurations"
},
"Next": {
"Name": "Swagger integration",
"Path": "solution-templates/single-layer-web-application/swagger-integration"
}
}
The ABP Studio single-layer solution template is fully configured for logging. All the applications are configured to use the Serilog library for structured logging. They are configured in a common way for logging. This document explains that common logging structure.
The Serilog library is configured so it writes the logs to the following targets (a.k.a. sinks) in parallel:
logs.txt located under the Logs folder of the executing application. File logging is useful when you run the application on your local computer. You can check logs easily when you have a trouble. This sinks is only configured for DEBUG mode. It won't be available in your production environment (you can change the behavior in your Program.cs file).The solution can work with any sink supported by Serilog. You can add more sinks, remove pre-installed sinks or fine tune their configuration for your solution.
The Program.cs file is the main point that configures the logging system. It is done here, because we want to initialize and start the logging in the very beginning of the application.
We are using ABP Serilog Enrichers in the module class of the application. It is done by the app.UseAbpSerilogEnrichers(); line in the OnApplicationInitialization method of your module class. That ASP.NET Core middleware adds current tenant, user, client and correlation id information to the log records.