This article is a mirror article of machine translation, please click here to jump to the original article.

View: 11155|Reply: 2

Logging System (II).NET/C# uses NLog to push logs to ELK

[Copy link]
Posted on 2/1/2021 5:54:26 PM | | | |
ASP.NET Core uses NLog to push logs to the ELK system, collecting and analyzing logs uniformly.

Log System (1) Windows Installation ELK 7.10.2 Tutorial
https://www.itsvse.com/thread-9539-1-1.html
First, let's take a look at the renderings, as follows:



Create a new ASP.NET Core 3.1 website project that references NLog.Web.AspNetCore as follows:

Create a new nlog.config configuration file and configure it as follows:

The program file is modified as follows:



We will write data to a file, as well asWriting to Elasticsearch via logstash, we send logging in UDP, why write to a file? Because UDP is unreliable and cannot 100% guarantee that all log data will be written to the ELK system normally, saving it to the local disk is equivalent to a backup.


Local logs are stored for up to 30 days, and logs older than 30 days are automatically cleaned up, which can be set through a profile.

Logstash creates a new test.conf configuration file as follows:

Start Logstash with the following command:

In the HomeController controller, call the log framework, access the Index page through the browser, and write 10,000 logs to the ELK system, the code is as follows:

Click Stack Management in the Kibana interface, select the index mode, click Create Index Mode in the upper right corner, and fill in itsvse-logs-*, as shown in the figure below:



After that, you can see the logs we recorded in Kibana's Discover interface.

Finally, attach the source code:

Tourists, if you want to see the hidden content of this post, pleaseReply





Previous:Deploy applications as Windows services through NSSM
Next:ASP.NET Core Link Trace (5) Jaeger data persists to elasticsearch
Posted on 1/11/2022 12:00:38 AM |
Learn to use NLog to push logs to ELK
 Landlord| Posted on 5/6/2024 10:11:37 AM |
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com