Update configuration settings and logging behavior for SQL monitoring
- Increased thresholds for maximum query and method executions per window to 500 and 250, respectively, to reduce false positives in loop detection. - Enabled logging of slow queries only, improving performance by reducing log volume. - Adjusted SQL query logging to capture only warnings and errors, further optimizing logging efficiency. - Updated various settings across appsettings files to reflect these changes, ensuring consistency in configuration.
This commit is contained in:
@@ -132,22 +132,18 @@ builder.Services.AddDbContext<ManagingDbContext>((serviceProvider, options) =>
|
||||
// Enable service provider caching for better performance
|
||||
options.EnableServiceProviderCaching();
|
||||
|
||||
// Enable comprehensive SQL query logging for monitoring and debugging
|
||||
// Enable SQL query logging for warnings and errors only (reduced logging)
|
||||
var logger = serviceProvider.GetRequiredService<ILogger<ManagingDbContext>>();
|
||||
var sentryMonitoringService = serviceProvider.GetRequiredService<SentrySqlMonitoringService>();
|
||||
|
||||
options.LogTo(msg =>
|
||||
{
|
||||
// Log SQL queries with enhanced formatting
|
||||
if (msg.Contains("Executed DbCommand") || msg.Contains("Executing DbCommand"))
|
||||
{
|
||||
Console.WriteLine($"[EF-SQL] {msg}");
|
||||
}
|
||||
else if (msg.Contains("Warning") || msg.Contains("Error"))
|
||||
// Log only warnings and errors to reduce log volume
|
||||
if (msg.Contains("Warning") || msg.Contains("Error"))
|
||||
{
|
||||
Console.WriteLine($"[EF-WARNING] {msg}");
|
||||
}
|
||||
}, LogLevel.Information); // Log all SQL operations for monitoring
|
||||
}, LogLevel.Warning); // Log only warnings and errors to reduce SQL log volume
|
||||
}, ServiceLifetime.Scoped); // Explicitly specify scoped lifetime for proper request isolation
|
||||
|
||||
// Add specific health checks for databases and other services
|
||||
|
||||
@@ -37,7 +37,9 @@
|
||||
"LoggingEnabled": false,
|
||||
"SentryEnabled": false,
|
||||
"LoopDetectionEnabled": true,
|
||||
"LogErrorsOnly": true
|
||||
"LogErrorsOnly": true,
|
||||
"MaxQueryExecutionsPerWindow": 500,
|
||||
"MaxMethodExecutionsPerWindow": 250
|
||||
},
|
||||
"Cors": {
|
||||
"AllowedOrigins": [
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
"LoggingEnabled": true,
|
||||
"SentryEnabled": false,
|
||||
"LoopDetectionEnabled": true,
|
||||
"LogSlowQueriesOnly": false
|
||||
"LogSlowQueriesOnly": true
|
||||
},
|
||||
"RunOrleansGrains": true,
|
||||
"AllowedHosts": "*",
|
||||
|
||||
@@ -96,12 +96,12 @@
|
||||
"LoopDetectionEnabled": true,
|
||||
"PerformanceMonitoringEnabled": true,
|
||||
"LoopDetectionWindowSeconds": 60,
|
||||
"MaxQueryExecutionsPesrWindow": 100,
|
||||
"MaxMethodExecutionsPerWindow": 50,
|
||||
"MaxQueryExecutionsPerWindow": 500,
|
||||
"MaxMethodExecutionsPerWindow": 250,
|
||||
"LongRunningQueryThresholdMs": 1000,
|
||||
"SentryAlertThreshold": 5,
|
||||
"SlowQueryThresholdMs": 1500,
|
||||
"LogSlowQueriesOnly": false,
|
||||
"LogSlowQueriesOnly": true,
|
||||
"LogErrorsOnly": false,
|
||||
"DataRetentionMinutes": 300
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user