Aller au contenu

Logging in loop (ARCH1004)

Ce contenu n’est pas encore disponible dans votre langue.

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.

foreach (var item in items)
{
_logger.LogInformation("Processing item {Id}", item.Id);
Process(item);
}
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.