How to replace this code:
string name = "John";
logger.Information("length of name '{name}' is {nameLength}", name, name.Length);
with C# String interpolation like this or similar
string name = "John";
// :-( lost benefit of structured logging: property names not passed to logger
logger.Information($"length of name '{name}' is {name.Length}");
but keep the property names for structured logging to work?
Benefits would be:
- Increased readability
- You'll never forget an argument in arguments list or a property name in message template, especially when you make changes to your logging code
- You always know what this property name will print to your log
FromSql
- it was all too easy to run an un-parameterized query, allowing SQL injection. That's why EF Core 3.1 replaced this withFromSqlRaw
,FromSqlInterpolated
and added theObsolete
attribute to the old method – Condition