dotnet / docs

This repository contains .NET Documentation.
https://learn.microsoft.com/dotnet
Creative Commons Attribution 4.0 International
4.17k stars 5.83k forks source link

Explanations required for this rule. #30471

Open franckleveque opened 1 year ago

franckleveque commented 1 year ago

[Enter feedback here] Hi,

It would be great to have an explanation on WHY this rule is in effect, I understand that positional parameter can be harmful in lengthy log message but not in short ones. So I don't really understand why I should force named parameter when I have only three parameters in my log.

ie : this.logger.LogInformation("Cache entry {0}_{1} exists : {2}", CacheId, requestId, result);


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

gewarren commented 1 year ago

@franckleveque I assume this is for the same reason that CA2254 exists:

When performing logging, it's desirable to preserve the structure of the log (including placeholder names) along with the placeholder values. Preserving this information allows for better observability and search in log aggregation and monitoring software.

That is, having a number for the key doesn't lend itself well to observability and searching in logs.

@Youssef1313 @maryamariyan If you agree, we can add this info to the article.