הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
| 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
שתף איתנו פעולה ב- GitHub
ניתן למצוא את המקור לתוכן זה ב- GitHub, שם ניתן גם ליצור ולסקור בעיות ולמשוך בקשות. לקבלת מידע נוסף, עיין במדריך התורמים שלנו.