Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
To write Serilog and EF Core messages to one file, register Serilog as ASP.NET Core’s Microsoft.Extensions.Logging provider and configure a file sink on that same Serilog logger. EF Core’s normal logging events then follow the shared provider pipeline. By contrast, DbContextOptionsBuilder.LogTo(Console.WriteLine) uses its own callback and does not automatically write to Serilog’s file.
Use one Serilog pipeline for application and EF Core logs
ASP.NET Core applications commonly emit logs through the ILogger abstraction from Microsoft.Extensions.Logging. The Serilog.AspNetCore integration routes those messages through Serilog, so framework and injected logger events can use the same levels and destinations. EF Core’s standard logging events use this provider pipeline too. The Serilog.AspNetCore project documentation describes routing ASP.NET Core messages through the same Serilog sinks as application events: Serilog.AspNetCore documentation.
Install the ASP.NET Core integration and file sink packages:
dotnet add package Serilog.AspNetCore
dotnet add package Serilog.Sinks.File
Then configure the host to use Serilog and add a file sink to that logger. This minimal-hosting example shows the intended arrangement:
#1 Best Overall
using Serilog;
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog((context, services, configuration) => configuration
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
.WriteTo.File("logs/app-.log", rollingInterval: RollingInterval.Day));
var app = builder.Build();
app.Run();
The Serilog getting-started documentation demonstrates WriteTo.File with daily rolling: Serilog documentation. The example path is relative to the application’s working directory; ensure the application identity can write to the target directory. The file sink does not create permission for a directory the process cannot access.
Choose the integration API for your project version
Serilog.AspNetCore APIs and overloads can vary by package version. Match the package’s major version to the application’s target framework, and check the installed release’s README for the exact registration method. The current project README also shows registration with builder.Services.AddSerilog(); the essential point is to register Serilog with the host’s logging provider pipeline, not merely to configure the static Log API. A static logger alone does not ensure that injected ILogger<T> or framework logs use it.
Rank #2
Do not confuse EF Core LogTo with the shared provider
EF Core’s DbContextOptionsBuilder.LogTo(...) is its simple-logging API. It invokes the callback you provide, so this sends messages to the console, not to the Serilog file sink:
optionsBuilder.LogTo(Console.WriteLine);
For one shared file, normally leave LogTo out and let EF Core emit its standard Microsoft.Extensions.Logging events through the registered Serilog provider. Use LogTo when you specifically want its independent callback-based diagnostic output. If that output must join Serilog, the callback needs to forward events explicitly into the same logging pipeline; it is not automatic. See Microsoft’s EF Core simple logging documentation.
Rank #3
Control which EF Core events reach the file
A shared destination does not mean every event is included. Minimum levels and category filters can exclude messages before they reach the sink. EF Core uses hierarchical categories; these are useful starting points when adjusting signal and volume:
Microsoft.EntityFrameworkCore.Database.Command— database commands.Microsoft.EntityFrameworkCore.Database.Transaction— transaction activity.Microsoft.EntityFrameworkCore.Query— query-related events.Microsoft.EntityFrameworkCore— broader EF Core activity.
For example, a Serilog category override can retain command information while leaving broader application logging less verbose:
.MinimumLevel.Information()
.MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", Serilog.Events.LogEventLevel.Information)
This is illustrative configuration, not a universal level prescription: choose levels appropriate to the events you need and the volume you can retain. Also check upstream logging configuration, because a filter there can prevent an event from reaching Serilog at all. Microsoft documents EF Core categories and filtering alongside simple logging at EF Core simple logging.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteDiagnose missing EF Core entries
- Confirm provider registration. Verify the host is configured to use Serilog, rather than only creating a static Serilog logger. Check the version-specific integration instructions in the Serilog.AspNetCore project documentation.
- Confirm the file sink belongs to that logger. The
WriteTo.File(...)configuration must be on the Serilog instance registered with the host. - Check the EF Core output path. If your DbContext options call
LogTowith a console or other callback, those messages are following that separate path. - Review minimum levels and category overrides. Check both the logging configuration upstream of Serilog and Serilog’s own category overrides, especially for
Microsoft.EntityFrameworkCore.Database.Command. - Check file access and shutdown. Ensure the process can write to the configured path, and close and flush the logger during orderly shutdown so buffered events can be written.
Flush the logger on orderly shutdown
Use a shutdown pattern that closes and flushes the logger. The Serilog.AspNetCore README shows this in a finally block; adapt its exact setup to the integration API used by your package version:
Quick Recap
Best Value
- Applying all key ASP.NET Core components, including MVC for HTML generation, .NET Core, EF Core, ASP.NET Identity, dependency injection, and more
- Integrating ASP.NET Core with leading client-side frameworks, including Bootstrap
- ASP.NET Core code for implementing business logic and data transformations
- Handling configuration, routing, controllers, views, and common tasks (including posting forms and presenting data)
- Performing complementary tasks: error handling, logging, application design, authentication, localization, and more
try
{
app.Run();
}
finally
{
Log.CloseAndFlush();
}
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

