org.sonar.plugins.csharp.S6678.html Maven / Gradle / Ivy
Within a message template each named placeholder should be in PascalCase.
Why is this an issue?
Using consistent naming conventions is important for the readability and maintainability of code. In the case of message templates, using
PascalCase for named placeholders ensures consistency with structured logging conventions, where each named placeholder is used as a property name in
the structured data.
The rule covers the following logging frameworks:
- Nuget package - Microsoft.Extensions.Logging
- Nuget package - Serilog
- Nuget package - Nlog
How to fix it
Use PascalCase for named placeholders.
Code examples
Noncompliant code example
logger.LogDebug("User {firstName} logged in", firstName); // Noncompliant
Compliant solution
logger.LogDebug("User {FirstName} logged in", firstName); // Compliant
Resources
Documentation
- Microsoft Learn - CA1727: Use PascalCase for
named placeholders
- Serilog Analyzer - Serilog006: Pascal Cased Property
Verifier
© 2015 - 2024 Weber Informatics LLC | Privacy Policy