Must-Know .NET NuGet Package: Serilog

Must-Know .NET NuGet Package: Serilog

🔧 Must-Know .NET NuGet Package: Serilog

Package: Serilog.AspNetCore
Purpose: Structured and flexible logging for .NET apps


Why Serilog?

  • Provides structured, readable logs (JSON, plain text, etc.)
  • Integrates seamlessly with ASP.NET Core logging
  • Supports rich log destinations (sinks): console, file, Seq, Azure, ElasticSearch, and more
  • Enables filtering, enrichment, correlation IDs, and more

Install:

dotnet add package Serilog.AspNetCore

Basic Setup in Program.cs

using Serilog;

public class Program
{
    public static void Main(string[] args)
    {
        Log.Logger = new LoggerConfiguration()
            .WriteTo.Console()
            .CreateLogger();

        CreateHostBuilder(args).Build().Run();
    }

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .UseSerilog() // Plug Serilog into the pipeline
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            });
}

Why It Matters:

Logging is the lifeline for debugging, observability, and production monitoring

Serilog makes logs machine-parsable and easy to search

Read more