Remove some logs from db

This commit is contained in:
2025-11-24 01:26:10 +07:00
parent fef66f6d7b
commit 9e3d8c74b9

View File

@@ -132,18 +132,8 @@ builder.Services.AddDbContext<ManagingDbContext>((serviceProvider, options) =>
// Enable service provider caching for better performance // Enable service provider caching for better performance
options.EnableServiceProviderCaching(); options.EnableServiceProviderCaching();
// Enable SQL query logging for warnings and errors only (reduced logging) // Disable SQL query logging to reduce log volume (only errors will be logged via standard logging)
var logger = serviceProvider.GetRequiredService<ILogger<ManagingDbContext>>(); // SQL monitoring is handled by SentrySqlMonitoringService which respects LogSlowQueriesOnly setting
var sentryMonitoringService = serviceProvider.GetRequiredService<SentrySqlMonitoringService>();
options.LogTo(msg =>
{
// Log only warnings and errors to reduce log volume
if (msg.Contains("Warning") || msg.Contains("Error"))
{
Console.WriteLine($"[EF-WARNING] {msg}");
}
}, LogLevel.Warning); // Log only warnings and errors to reduce SQL log volume
}, ServiceLifetime.Scoped); // Explicitly specify scoped lifetime for proper request isolation }, ServiceLifetime.Scoped); // Explicitly specify scoped lifetime for proper request isolation
// Add specific health checks for databases and other services // Add specific health checks for databases and other services
@@ -177,6 +167,7 @@ builder.Host.UseSerilog((hostBuilder, loggerConfiguration) =>
}; };
loggerConfiguration loggerConfiguration
.MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", LogEventLevel.Warning) // Filter out EF Core SQL query logs
.WriteTo.Console() .WriteTo.Console()
.WriteTo.Elasticsearch(es); .WriteTo.Elasticsearch(es);
}); });