docs
docs copied to clipboard
Dont understand why - and would like to.
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.
- ID: f5662dc7-dcf6-47d5-9340-55b22ebfeca8
- Version Independent ID: 0df9ae80-f763-ba60-a876-a98e86d64887
- Content: CA2254: Template should be a static expression - .NET
- Content Source: docs/fundamentals/code-analysis/quality-rules/ca2254.md
- Product: dotnet-fundamentals
- GitHub Login: @Youssef1313
- Microsoft Alias: gewarren
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.
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.