When using the Microsoft.Extensions.Logging.ILogger<T>
with message templates for structured logging, Visual Studio highlights the message template “named holes”/parameters like this (see {Address}
):
Is it possible to achieve the same highlighting effect at the call site for one of your own methods?
If so, how? What are the mechanics behind the highlighting?
Background (but I’m curius in the general case):
We’re using an exception filter method as discussed here, like this:
public static class LoggerExtensions
{
public static bool LogExceptionNoCatch<T>(this ILogger<T> logger, Exception exception, string? message, params object?[] args)
{
logger.LogError(exception, message, args);
return false;
}
// ...
}
However, when using this extension method there is no highlighting indicating that message templates is being used: