Starts in:
3 DAYS
4 HRS
35 MIN
30 SEC
Starts in:
3 D
4 H
35 M
30 S

Microservice Solution: Logging

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 Sinks

The Serilog library is configured so it writes the logs to the following targets (a.k.a. sinks) in parallel:

  • Console: Logs are written to the standard output of the executing application. Logging to console is useful when you want to see logs easily while it is running in a container.
  • File: Logs are written to a file named 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).
  • ElasticSearch: Logs are sent to an Elasticsearch server. Elasticsearch is especially useful when you want to search and trace the logs. This microservice solution is also includes a Kibana container configuration, so you can visualize and search your logs easily. See your appsettings.json file for the Elasticsearch configuration.
  • ABP Studio: This is a Sink provided by ABP Studio. It sends all logs to ABP Studio, so you can easily monitor your logs in real-time on your ABP Studio Application Monitoring panel.

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.

Program.cs

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.

Additional Information

You can easily understand the Serilog configuration when you check your Program.cs. However, there are a few things worth mentioning here:

  • We are adding an 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.
  • 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.

Contributors


Last updated: July 31, 2024 Edit this page on GitHub

Was this page helpful?

Please make a selection.

To help us improve, please share your reason for the negative feedback in the field below.

Please enter a note.

Thank you for your valuable feedback!

Please note that although we cannot respond to feedback, our team will use your comments to improve the experience.

In this document
Community Talks

What’s New with .NET 9 & ABP 9?

21 Nov, 17:00
Online
Watch the Event
Mastering ABP Framework Book
Mastering ABP Framework

This book will help you gain a complete understanding of the framework and modern web application development techniques.

Learn More