docs icon indicating copy to clipboard operation
docs copied to clipboard

Dont understand why - and would like to.

Open psiservices-andrewfreese opened this issue 2 years ago • 1 comments

Article says "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." It would be beneficial to understand why. Seems like the log "receives" a string. Want to understand how sending an interpolated string could "lower observability".


Document Details

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

Hi @psiservices-andrewfreese - thank you for posting this issue, we really appreciate it. These error articles focus on the general case for the error, but not specific situations that cause them so to speak. With that said, see: .NET Docs, Logging in .NET: Log message template formatting. Using string interpolation in the logging APIs is a performance issue.

IEvangelist avatar Sep 08 '22 18:09 IEvangelist

Hi @psiservices-andrewfreese - thank you for posting this issue, we really appreciate it. These error articles focus on the general case for the error, but not specific situations that cause them so to speak. With that said, see: .NET Docs, Logging in .NET: Log message template formatting. Using string interpolation in the logging APIs is a performance issue.

Performance issues are not mentioned anywhere in the explanation for CA2254.

What its trying to say is that logs should use a regular template with separate parameters, to make log aggregation easier to perform.

So instead of your logs looking like this;

Could not find Foos for user Bob Bobson
Could not find Foos for user Alice Aliceworth

Which is difficult to aggregate, it wants your messages to look like this;

Could not find Foos for user {firstName} {lastName}
Could not find Foos for user {firstName} {lastName}

So here, we see that there were two instances of not being able to find foos.

It needs to be re-written so that this is clear.

gavinBurtonStoreFeeder avatar Nov 15 '22 11:11 gavinBurtonStoreFeeder