Generic Host and Entity Framework Logging Configuration
Describe the bug
I'm using the generic host builder to construct a host for my local service. Logging is configured with a logging level of Error across the board. This is working except in EF Core which is still logging at the info level. I suspect that EF is using a separate logger. Is there something different I need to do to tell EF to use the same log configuration as the rest of the application. Below is the code for my host
`
public static async Task Main(string[] args)
{
var host = new HostBuilder()
.ConfigureHostConfiguration(configHost =>
{
configHost.SetBasePath(Directory.GetCurrentDirectory());
configHost.AddJsonFile("hostsettings.json", optional: true);
configHost.AddEnvironmentVariables(prefix: "PREFIX_");
configHost.AddCommandLine(args);
})
.ConfigureAppConfiguration((hostContext, configApp) =>
{
configApp.AddJsonFile("appsettings.json", optional: true);
configApp.AddJsonFile(
$"appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json",
optional: true);
configApp.AddCommandLine(args);
})
.ConfigureServices((hostContext, services) =>
{
// register ABS data context
var configuration = hostContext.Configuration;
services.AddDbContext<AbsContext>(options =>
{
options.UseSqlServer(configuration.GetConnectionString("AbsConnection"));
});
services.AddAutoMapper();
// register Safesforce configuration
var sfconfig = new SalesForceConfiguration();
configuration.Bind(nameof(SalesForceConfiguration), sfconfig);
services.AddSingleton(sfconfig);
// register Salesforce Data Context
services.AddSingleton<DataManager>();
// register repositories
services.AddSingleton<IAbsRepository, EfAbsRepository>();
services.AddSingleton<ISalesForceRepository, RestApiSalesForceRepository>();
// register engines
services.AddSingleton<ISalesForceEngine, DefaultSalesForceEngine>();
services.AddSingleton<IAbsEngine, DefaultAbsEngine>();
// register manager
services.AddSingleton<IProviderManager, DefaultProviderManager>();
// register hosted applications
services.AddHostedService<ProviderUpdateService>();
})
.ConfigureLogging((hostContext, configLogging) =>
{
configLogging.AddConsole();
configLogging.AddDebug();
configLogging.AddEventLog();
})
.Build();
await host.StartAsync();
await host.StopAsync();
host.Dispose();
}`
Here is the loglevel currently configured on both my appsettings files:
{
"Logging": {
"LogLevel": {
"ARA": "Information",
"Default": "Error",
"System": "Error",
"Microsoft": "Error"
}
}
}
Here is what gets logged. ARA object get logged at info like they should, but the EF logs should be at Error, but are also logging at info:

Found it...
needed to add
builder.AddConfiguration(context.Configuration.GetSection("Logging"));
to my ConfigureLog() call.
Looks like the sample project for Generic Host needs it too...