หมายเหตุ
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลอง ลงชื่อเข้าใช้หรือเปลี่ยนไดเรกทอรีได้
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลองเปลี่ยนไดเรกทอรีได้
| 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 ซึ่งคุณยังสามารถสร้างและตรวจสอบปัญหาและคำขอดึงข้อมูลได้ สำหรับข้อมูลเพิ่มเติม ให้ดูคู่มือผู้สนับสนุนของเรา