Logging using Serilog- ASP .Net Core 5

KANHAIYA TYAGI
2 min readMay 26, 2021

Serilog is a structural logging library for Microsoft .Net and has become the preferred logging library for .Net applications. I used in Asp .Net core Web Application to configure the serilog. I created logs in text file and on console.

  • Serilog’s vast ecosystem consisting of hundreds of integrations that cover Console Write, File Write, Message Queue, Database Write, Elastic Search, Azure Event Hub etc.
  • Simple API and easy to extend.
  • The capability of seamless switching the output format to either plain text or JSON.
  • Less Configuration from other logger’s.

Steps

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

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

5. Add Serilog configuration in appsettings.json and also appsettings.Development.json and remove default logging from both JSON files.

Configuration in appsettings.json

6.Add Serilog into startup.cs file.

Startup.cs

7.Use into the controller like this

ValueController.cs

GitHub Link : XearoSeriLog

I hope you like the article. In case, you find the article interesting then kindly like and share it.

--

--

KANHAIYA TYAGI

Engineer, GIS, .NET, JavaScript, jQuery, Azure, Angular