إشعار
يتطلب الوصول إلى هذه الصفحة تخويلاً. يمكنك محاولة تسجيل الدخول أو تغيير الدلائل.
يتطلب الوصول إلى هذه الصفحة تخويلاً. يمكنك محاولة تغيير الدلائل.
| 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 حيث يمكنك أيضاً إضافة مشاكل وطلبات سحب ومراجعتها. للحصول على معلومات إضافية، اطلع على دليل المساهم لدينا.