sting.Format suggestion #100259
Replies: 3 comments 5 replies
-
So effectively, you are asking for replacing placeholder indexes with names. Generally we are suggesting moving away from |
Beta Was this translation helpful? Give feedback.
-
@stephentoub Thoughts? Should we expose LogValuesFormatter. I'm not sure how common this scenario is. |
Beta Was this translation helpful? Give feedback.
-
I just stumble upon this when looking for a way to use named placeholders for string.Format. My use case is a bit different so I wanted to chime in as well. I have API routes defined as constant strings and the route parameters: public const string RouteParameterOperationId = "operationId";
public const string Route = $"/operations/{{{RouteParameterOperationId}}}/permitfile"; Then I want to use the I still want to keep the route parameter name and not change it to |
Beta Was this translation helpful? Give feedback.
-
Hi,
My team uses the new ILogger from the Microsoft.Extensions.Logging library and are running into an issue utilizing the Message Template format with the
Logger.LogError
method and with thestring.Format
method. See use case below.In this case, we're creating a custom dimension for the user in our logs but the message returned to our user would be "{User} not found". If we tried to utilize the
string.Format
method it fails because it expectsstring.format("{0}", user)
. Atm I've written a custom extension method to parse this out but I'd imagine this is a use case for everyone following this pattern. Could this be included as another overload for string.Format in the future or possibly a different method altogether?Thnx
Beta Was this translation helpful? Give feedback.
All reactions