Our low-level logging library should handle all kinds of log messages sent to it.
Some of these messages include braces (as part of the text), and some contain parameters that must be formatted as part of the string using String.Format
For example, this line may be an entry in the Logger class:
"Parameter: {Hostname} Value: {0}" Using the correct variable sent for use for formatting.
To do this correctly, I must avoid curly braces that are not part of the formatting (by doubling them).
I was thinking of doing this with Regex, but it's not as simple as it might seem, since I have no idea how to match these strings inside curly braces (those that are NOT used by String.Format for formatting).
Another problem is that the Logger class should be as efficient as possible, starting with regular expressions, as part of its work may interfere with the work.
Is there any good and known best practice for this?
source share