I have a Data.Migrations project, which will run any Entity Framework Migrations to update the database model.
Recently I have updated this project to .NET 6 and added a logger to the Program.cs using the following code:
var serviceCollection = new ServiceCollection();
var serviceProvider = serviceCollection.BuildServiceProvider();
_logger = serviceProvider.GetService<ILogger<Program>>();
This results however in _logger == null.
How can I add a logger to the Program.cs?
If you're using a minimal hosting model, it`s pretty simple:
...
var app = builder.Build();
app.Logger.LogInformation("Starting Application");
...
The preceding code is show in the official ASP.NET Core docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With