-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Is your feature request related to a problem? Please describe.
I am using some attributes from OpenTelemetry semantic conventions, like process.exit.code
, as placeholder names in log message templates. The intention is to make these log entries searchable in the same way as activities. However, the CA1727 analyzer warns about such names. I have disabled the warnings by setting dotnet_diagnostic.CA1727.severity = none
in .editorconfig
but now it doesn't warn about camelCase
names either.
Describe the solution you'd like
Add to the CA1727 analyzer an opt-in mode in which it allows both PascalCase
names (.NET convention) and dotted.lower.case
names (OTel convention), where the OTel attribute name
- consists only of lower-case letters, digits, dots, and underscores
- and contains at least one dot
as per General naming considerations.
It could be enabled with a new dotnet_code_quality.CA1727.allow_dotted_lowercase
setting in .editorconfig
.
Alternatively, .editorconfig
could specify a regular expression and the analyzer would then allow names that match that. However, none of the existing options for analyzers seem to take a regex, and there might be a risk of denial-of-service attack if the regex is malicious.
Another alternative would be to implement a DiagnosticSuppressor for those names. However, the CA1727 diagnostic does not mention the placeholder name itself, and the Location of the diagnostic refers to the entire log message template, so the suppressor would have to parse the template again and reimplement most of the CA1727 analyzer.
Additional context
Because dotted names like process.exit.code
are not valid as identifiers in C#, using them with compile-time logging source generation would require TagNameAttribute.
Inspired by dotnet/roslyn-analyzers#6051 / #50766.