From edf2468a335c5ffe19e945fcda9fb25064c519ab Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 3 Dec 2025 11:47:54 +0100 Subject: [PATCH] Enhance DbContext configuration with logging features Added advanced logging and debugging capabilities to the DbContext configuration in `AddRecInfrastructure`: - Integrated `ILogger` 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. --- src/ReC.API/Program.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ReC.API/Program.cs b/src/ReC.API/Program.cs index 0d0204a..1887ee2 100644 --- a/src/ReC.API/Program.cs +++ b/src/ReC.API/Program.cs @@ -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>(); + dbContextOpt.UseSqlServer(connectionString) + .LogTo(log => logger.LogInformation("{log}", log), Microsoft.Extensions.Logging.LogLevel.Trace) + .EnableSensitiveDataLogging() + .EnableDetailedErrors(); }); });