Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/fundamentals/code-analysis/quality-rules/ca2253.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ helpviewer_keywords:
- LoggerMessageDefineAnalyzer
- CA2253
author: Youssef1313
dev_langs:
- CSharp
---
# CA2253: Named placeholders should not be numeric values

Expand All @@ -34,6 +36,10 @@ Rename the numeric placeholder.

For usage examples, see the <xref:Microsoft.Extensions.Logging.LoggerExtensions.LogInformation%2A?displayProperty=nameWithType> method.

## Example

:::code language="csharp" source="snippets/csharp/all-rules/ca2253.cs" id="snippet1":::

## When to suppress errors

Do not suppress a warning from this rule.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.Extensions.Logging;

namespace ca2253
{
//<snippet1>
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);

// ...
}
}
//</snippet1>
}