docs/en/solution-templates/microservice/logging.md
//[doc-seo]
{
"Description": "Explore how to implement structured logging in your ABP microservice solution using Serilog, ensuring efficient log management across services."
}
//[doc-nav]
{
"Next": {
"Name": "Monitoring in the Microservice solution",
"Path": "solution-templates/microservice/monitoring"
}
}
You must have an ABP Business or a higher license to be able to create a microservice solution.
The ABP Studio microservice solution template is fully configured for logging. All the services, applications and gateways 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).appsettings.json file for the Elasticsearch configuration.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.
You can easily understand the Serilog configuration when you check your Program.cs. However, there are a few things worth mentioning here:
Application property to every log record, so you can filter logs by the application name. It is done in the Program.cs file with the .Enrich.WithProperty("Application", applicationName) line. The applicationName value is taken from the IApplicationInfoAccessor service of ABP. By default, it is the name of the entrance assembly (that contains the Program.cs file) of the application.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.