Improved logging support for efbundle
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
I would like `efbundle` to use my logging configuration.
I use Serilog to log in a JSON format, including from my `DbContext`, e.g.
```
public class MyDatabaseContext(ILogger logger) : DbContext
{
readonly ILogger _log = logger.ForContext();
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql(...);
optionsBuilder.UseLoggerFactory(Microsoft.Extensions.Logging.LoggerFactory.Create(logger =>
{
logger.AddSerilog();
}));
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
_log.Information("Some useful information...");
}
...
}
```
When running a packaged `efbundle` to apply migrations, messages from within the context will be logged as JSON, but messages from the bundle tool itself are written raw to `stdout`. This mixing of log formats makes it difficult when streamed to something like Datadog:

The `efbundle` tool is already picking up the `DbContext` and its logging configuration from the startup project. Could we also have it use the logging infrastructure? Possible solutions:
* Automatically pick up the logging configuration from the same host builder.
* An explicit logging factory or hook for the migrations.
* Extending the design time context factory (https://learn.microsoft.com/en-us/ef/core/cli/dbcontext-creation?tabs=dotnet-core-cli#from-a-design-time-factory).
Contributor guide
Assessment
This issue has not been assessed yet.