runtime: LoggerMessageAttribute doesn't support parameters with dots

Description

Hi,

first of all, I really like the LoggerMessageAttribute 👍, but I have a “small” problem why I can’t use it: In order to align with our custom tags from our OpenTelemetry traces we want to use parameters with dots in the name. Something like this “messaging.id” or “messaging.type”.

It’s not possible to do that with the LoggerMessageAttribute as it’s not possible to include a “dot” in the c# parameter or did I missed something?

My issue is similar to https://github.com/dotnet/runtime/issues/60968, but it’s not the same as my example is about a dot and not a @.

Reproduction Steps

This doesn’t compile:

[LoggerMessage(Level = LogLevel.Information, EventName = "LogMessage",
        Message = "The event {messaging.id} of type {messaging.type} did something")]
public static partial void LogMyMessage(this ILogger logger, string messaging.id, string messaging.type);

If I try to use something do it like this the code generated from the code generator is not compiling:

[LoggerMessage(Level = LogLevel.Information, EventName = "LogMessage",
        Message = "The event {messaging.id} of type {messaging.type} did something")]
public static partial void LogMyMessage(this ILogger logger, string messaging_id, string messaging_type);

Expected behavior

Be able to use it with a parameter that has a “dot” 😀

Actual behavior

Code is not compiling.

Regression?

No response

Known Workarounds

No response

Configuration

.Net 6.0

Other information

No response

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

I can’t currently use the source generator with its lack of @ destructuring support;

Just FYI, https://github.com/dotnet/runtime/pull/79038