What
We should write log calls so they comply with CA2254 – Template should be a static expression.
Why it matters
-
Structured placeholders (
"... {SchemaId}"+ arg) are captured as named properties by Seq / Elastic / App Insights — interpolated strings ($"... {id}") lose them and become plain text. -
Every interpolated message becomes a new template hash → cardinality blow-up in log aggregators, breaks grouping and sampling.
-
The
messageargument is also formatted even when the level is filtered out; the constant template form lets the framework defer formatting.
Do
logger.LogWarning(ex, "Orphaned reference for schema item {SchemaId}", item.Id);
Don’t
logger.LogWarning(ex, $"Orphaned reference for schema item {item.Id}");
My conclusion
What do you think about it? Is it relevant? Would it be worth rewriting Origam.Architect.Server into a static expression? And maybe even in Origam.Server.
Reference