formattablestring

C# Serilog: how to log with String interpolation and keep argument names in message templates?

左心房为你撑大大i 提交于 2020-05-30 06:45:27
问题 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

C# Serilog: how to log with String interpolation and keep argument names in message templates?

安稳与你 提交于 2020-05-30 06:44:05
问题 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

Difference between String, FormattableString, IFormattable

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 19:58:01
FormattableString has been Introduced in C# 6.0. As we can use same string formatting using string object why is there need of using FormattableString or IFormattable . Whats difference between three? My Code var name = "Pravin"; var s = $"Hello, {name}"; System.IFormattable s1 = $"Hello, {name}"; System.FormattableString s2 = $"Hello, {name}"; Above all there produces same result. i.e 'Hello Pravin'. Can I get more elaborated answer on this if anyone has deep knowledge on same. FormattableString is a new type in .NET 4.6, and the compiler will only use it if you try to use it. In other words,

Difference between String, FormattableString, IFormattable

拥有回忆 提交于 2019-11-30 11:50:01
问题 FormattableString has been Introduced in C# 6.0. As we can use same string formatting using string object why is there need of using FormattableString or IFormattable . Whats difference between three? My Code var name = "Pravin"; var s = $"Hello, {name}"; System.IFormattable s1 = $"Hello, {name}"; System.FormattableString s2 = $"Hello, {name}"; Above all there produces same result. i.e 'Hello Pravin'. Can I get more elaborated answer on this if anyone has deep knowledge on same. 回答1: