public static void Log(CosmosDiagnostics cosmosDiagnostics) { TimeSpan elapsedTime = cosmosDiagnostics.GetClientElapsedTime(); // Require the diagnostics to be at least 10 seconds apart to avoid getting the // diagnostics from the exact same time frame to avoid the same issue multiple times if (stopwatch.Elapsed > CosmosDiagnosticsLogger.minimumDelayBetweenDiagnostics && elapsedTime > CosmosDiagnosticsLogger.maxTimeSpan) { // This can be called concurrently by multiple tasks. Take a lock and // validate the check again and update the times. lock (CosmosDiagnosticsLogger.UpdateLock) { if (stopwatch.Elapsed <= CosmosDiagnosticsLogger.minimumDelayBetweenDiagnostics && elapsedTime <= CosmosDiagnosticsLogger.maxTimeSpan) { return; } stopwatch.Restart(); maxTimeSpan = elapsedTime; } CosmosDiagnosticsLogger.CosmosDiagnosticsToLog.Enqueue(cosmosDiagnostics); if (CosmosDiagnosticsToLog.Count > MaxSize) { CosmosDiagnosticsToLog.TryDequeue(out _); } } }