Logging in loop (ARCH1004)
هذا المحتوى غير متوفر بلغتك بعد.
Key dotnet.logging.logging-in-loop · Severity info · Category logging
Logging on every loop iteration inflates log volume and degrades performance. Prefer a summary or aggregate log instead.
Incorrect
Section titled “Incorrect”foreach (var item in items){ _logger.LogInformation("Processing item {Id}", item.Id); Process(item);}Correct
Section titled “Correct”foreach (var item in items){ Process(item);}_logger.LogInformation("Processed {Count} items", items.Count);Move the log call out of the loop into a single summary message, or log only on error conditions.