How to Combine Serilog and EF Core Logs into One File in ASP.NET Core

A technical guide published on DEV Community explains how to route both standard application logs and Entity Framework Core database command logs into a single daily rolling log file using Serilog in ASP.NET Core. The setup requires several NuGet packages, including Serilog.AspNetCore and Serilog.Sinks.File, along with specific configuration entries in appsettings.json. Developers must override the default log level for the Microsoft.EntityFrameworkCore.Database.Command namespace to Information so that SQL commands are captured alongside regular messages. The configuration is wired into the application via Program.cs using the UseSerilog host extension, which reads settings from the app's configuration and enriches log context automatically. An optional project-level flag allows developers to split the output into two separate files — one for general logs and one exclusively for EF Core — if a combined file is not preferred.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in