In a .NET C# application with Microsoft logging, one will have logging statements like the following, with a message that may include brace-delimited placeholders followed by an ordered sequence of values to fill the placeholders with:
logger.LogInformation("{numRequests} orders for {item} were received in the past hour", 47, "doughnuts");
If the number of parameters after the message parameter differs from the number of placeholders, Visual Studio, flags the discrepancy. How does Visual Studio know?
- Is Visual Studio hard-coded to recognize Microsoft Logging statements and apply special treatment to them? In other words, not something I could replicate when defining a method of my own where I’d like this to occur.
- Or is there a generally available way of declaring a string parameter as a template and associating it with a parameter array? Could I use this in a method declaration of my own?
Yes, I know about formattable strings, but I’m curious about what’s behind the way it works in the logging methods, without formattable strings.