Enhance DbContext configuration with logging features

Added advanced logging and debugging capabilities to the
DbContext configuration in `AddRecInfrastructure`:
- Integrated `ILogger<RecDbContext>` for logging.
- Enabled SQL query logging with `LogTo` at `Trace` level.
- Enabled sensitive data logging for debugging purposes.
- Enabled detailed error messages for better diagnostics.
This commit is contained in:
tekh 2025-12-03 11:47:54 +01:00
parent 60e5adbf1a
commit edf2468a33

View File

@ -20,7 +20,12 @@ builder.Services.AddRecInfrastructure(options =>
{
var connectionString = builder.Configuration.GetConnectionString("Default")
?? throw new InvalidOperationException("Connection string is not found.");
dbContextOpt.UseSqlServer(connectionString);
var logger = provider.GetRequiredService<ILogger<RecDbContext>>();
dbContextOpt.UseSqlServer(connectionString)
.LogTo(log => logger.LogInformation("{log}", log), Microsoft.Extensions.Logging.LogLevel.Trace)
.EnableSensitiveDataLogging()
.EnableDetailedErrors();
});
});