Nóta
Aðgangur að þessari síðu krefst heimildar. Þú getur prófað aðskrá þig inn eða breyta skráasöfnum.
Aðgangur að þessari síðu krefst heimildar. Þú getur prófað að breyta skráasöfnum.
| Property | Value |
|---|---|
| Rule ID | CA2253 |
| Title | Named placeholders should not be numeric values |
| Category | Usage |
| Fix is breaking or non-breaking | Non-breaking |
| Enabled by default in .NET 10 | As suggestion |
Cause
A message placeholder consists of numeric characters only.
Rule description
Named placeholders in the logging message template should not be composed of only numeric characters.
How to fix violations
Rename the numeric placeholder.
For usage examples, see the LoggerExtensions.LogInformation method.
Example
public class UserService
{
private readonly ILogger<UserService> _logger;
public UserService(ILogger<UserService> logger)
{
_logger = logger;
}
public void Add(string firstName, string lastName)
{
// This code violates the rule.
_logger.LogInformation("Adding user with first name {0} and last name {1}", firstName, lastName);
// This code satisfies the rule.
_logger.LogInformation("Adding user with first name {FirstName} and last name {LastName}", firstName, lastName);
// ...
}
}
When to suppress errors
Do not suppress a warning from this rule.
See also
Vertu í samstarfi við okkur á GitHub
Heimildina fyrir þetta efni er að finna á GitHub, þar sem þú getur líka búið til og farið yfir vandamál og sameinað beiðnir. Frekari upplýsingar er að finna í framlagshandbók okkar.