Kanhaya Tyagi
Logging using Serilog- ASP .Net Core 5
- Serilog is a structural logging library for Microsoft .Net and has become the preferred logging library for .Net applications. I used Asp .Net core Web Application to configure the serilog. I created logs in a text file and on the console.
- Serilog’s vast ecosystem consists of hundreds of integrations covering Console Write, File Write, Message Queue, Database Write, Elastic Search, Azure Event Hub, etc.
- Simple API and easy to extend.
- The capability of seamlessly switching the output format to either plain text or JSON.
Less Configuration from other loggers.
Steps
- Create an ASP .Net Core Web Application project name as “SeriLogger.”
- Add/Create class library name as “Logger” in .Net core into the SeriLogger project and add a reference into the Serilogger.
- Add below NuGet packages in the “Logger” class library.
- Create a new class in Logger class library “HostBuilderExtensions”
- Add Serilog configuration in appsettings.json and appsettings. Development.json and remove default logging from both JSON files.
6.Add Serilog into startup.cs file.
7.Use into the controller like this
GitHub Link : XearoSeriLog
I hope you like the article. If you find the article interesting, kindly like and share it.