From 819b7d7443de2e75953c31e760de369fa236cf83 Mon Sep 17 00:00:00 2001 From: Reuben Bond <203839+ReubenBond@users.noreply.github.com> Date: Fri, 24 Jan 2025 13:39:21 -0800 Subject: [PATCH] Use 'LogWarning' method in examples The current method used by examples, `Warning`, does not exist --- docs/fundamentals/code-analysis/quality-rules/ca2254.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2254.md b/docs/fundamentals/code-analysis/quality-rules/ca2254.md index edb6b3bc8cb03..ed800bda2e70c 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2254.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2254.md @@ -36,7 +36,7 @@ var lastName = "Otto"; // This tells the logger that there are FirstName and LastName properties // on the log message, and correlates them with the argument values. -logger.Warning("Person {FirstName} {LastName} encountered an issue", firstName, lastName); +logger.LogWarning("Person {FirstName} {LastName} encountered an issue", firstName, lastName); ``` Not preferred: @@ -48,10 +48,10 @@ var firstName = "Lorenz"; var lastName = "Otto"; // Here, the log template itself is changing, and the association between named placeholders and their values is lost. -logger.Warning("Person " + firstName + " " + lastName + " encountered an issue"); +logger.LogWarning("Person " + firstName + " " + lastName + " encountered an issue"); // String interpolation also loses the association between placeholder names and their values. -logger.Warning($"Person {firstName} {lastName} encountered an issue"); +logger.LogWarning($"Person {firstName} {lastName} encountered an issue"); ``` The logging message template should not vary between calls. @@ -61,7 +61,7 @@ The logging message template should not vary between calls. Update the message template to be a constant expression. If you're using values directly in the template, refactor the template to use named placeholders instead. ```csharp -logger.Warning("Person {FirstName} {LastName} encountered an issue", firstName, lastName); +logger.LogWarning("Person {FirstName} {LastName} encountered an issue", firstName, lastName); ``` For usage examples, see the method.