Kanhaya Tyagi

Logging using Serilog- ASP .Net Core 5

By Kanhaya Tyagi

Last updated cal_iconDecember 16, 2021

  • 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

  1. Create an ASP .Net Core Web Application project name as “SeriLogger.”
  2. Add/Create class library name as “Logger” in .Net core into the SeriLogger project and add a reference into the Serilogger.
  3. Add below NuGet packages in the “Logger” class library. 

  1. Create a new class in Logger class library “HostBuilderExtensions”

  1. 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.

Get In Touch

How Can We Help ?

We make your product happen. Our dynamic, robust and scalable solutions help you drive value at the greatest speed in the market

We specialize in full-stack software & web app development with a key focus on JavaScript, Kubernetes and Microservices
Your path to drive 360° value starts from here
Enhance your market & geographic reach by partnering with NodeXperts