Register Serilog as ASP.NET Core’s Microsoft.Extensions.Logging provider and configure a file sink on that same Serilog logger. EF Core’s ordinary logging events then flow through the shared pipeline into the file. By contrast, DbContextOptionsBuilder.LogTo(...) is a separate simple-logging callback; it will not reach that file automatically.
Set up one Serilog pipeline for the application and EF Core
ASP.NET Core applications use the Microsoft.Extensions.Logging abstraction for framework and injected ILogger<T> messages. The Serilog ASP.NET Core integration connects that pipeline to Serilog, allowing application and framework events to use the same levels and destinations. EF Core’s normal logging events use this Microsoft logging pipeline too. See the ASP.NET Core logging documentation and the Serilog.AspNetCore project documentation.
As an Amazon Associate I earn from qualifying purchases.
For a modern minimal-hosting application, the arrangement looks like this:
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 key is that the file sink belongs to the Serilog logger registered with the host. Configuring only Serilog’s static Log API does not, on its own, route injected ILogger<T> events through that logger.
#1 Best Overall
Serilog.AspNetCore’s current README also demonstrates registering Serilog with builder.Services.AddSerilog() and closing and flushing the logger in a finally block. The precise overloads and registration pattern depend on the installed Serilog.AspNetCore release. Select a package major version that matches the application’s target framework and verify the API signature against that release’s README rather than copying a version-specific example blindly.
Install the integration and file sink
Add the ASP.NET Core integration and file sink packages:
Rank #2
dotnet add package Serilog.AspNetCore
dotnet add package Serilog.Sinks.File
Serilog’s getting-started documentation shows Serilog.Sinks.File and the WriteTo.File(..., rollingInterval: RollingInterval.Day) pattern. ASP.NET Core does not include a built-in general-purpose file logging provider, so a Serilog sink supplies the file destination.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Make sure EF Core is using the shared provider
EF Core logs written through Microsoft.Extensions.Logging will use Serilog once Serilog is registered as the application’s provider. You generally do not need to add a separate logging call to the DbContext just to put those events in the same file.
Do not add optionsBuilder.LogTo(Console.WriteLine) expecting it to join the Serilog pipeline. EF Core’s LogTo API invokes the callback you provide, so Console.WriteLine sends those messages to the console instead. If you intentionally use LogTo, its callback must explicitly forward events to the desired logging pipeline; otherwise it remains an independent output path. See Microsoft’s EF Core simple logging documentation.
Choose categories and levels so database events are retained
Shared output does not guarantee that every EF Core event will appear. Category and minimum-level filters can exclude events before they reach the file sink. EF Core uses hierarchical categories, including:
Microsoft.EntityFrameworkCore.Database.Commandfor database commands.Microsoft.EntityFrameworkCore.Database.Transactionfor transactions.Microsoft.EntityFrameworkCore.Queryfor queries.Microsoft.EntityFrameworkCorefor broader EF Core logging.
Use Serilog category overrides to adjust the signal—for example, retaining database command information without lowering the application-wide minimum level. Check the effective configuration at runtime, including any Microsoft logging filters: a filter upstream of Serilog can prevent an event from reaching the sink. EF Core’s simple-logging documentation describes its own minimum-level, event-ID, category, and predicate filters; those controls apply to the separate LogTo route.
Diagnose missing EF Core entries
- Verify provider registration. Confirm the host’s Microsoft logging pipeline is connected to Serilog, rather than configuring only the static Serilog logger.
- Verify the sink and path. Confirm the File sink is attached to that registered logger and that the application identity can write to the configured directory.
- Check the EF Core output path. Look for a
LogTocallback writing somewhere else, such as the console. It does not automatically use the Serilog sink. - Check category and level filters. Ensure the effective settings permit the relevant EF Core categories, especially
Microsoft.EntityFrameworkCore.Database.Command, at the events’ levels. - Close the logger during orderly shutdown. Follow the integration’s shutdown pattern to flush and dispose of the logger; the Serilog.AspNetCore README demonstrates closing and flushing in
finally. - Check version alignment. Confirm the Serilog.AspNetCore major version and registration API are appropriate for the application’s target framework.
When to use EF Core LogTo instead
LogTo can be useful for focused diagnostics when a callback-based output is what you want. EF Core’s simple logging defaults to Debug and higher and supports filtering by level, event ID, category, or a custom predicate. Its formatting options include multiline output by default, UTC timestamps, and single-line output. These controls belong to the direct-output callback and do not make it part of Serilog’s structured pipeline.
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
For a shared application log file, the simpler fit is Microsoft.Extensions.Logging → Serilog → File sink. Use LogTo as a separate diagnostic route when that separation is intentional, or explicitly forward its callback if it must share a destination.
Quick Recap
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.




