Skip to content

Update article and code to use PascalCase for placeholders #37446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 12, 2023
Merged
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
32 changes: 15 additions & 17 deletions docs/core/extensions/logger-message-generator.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
---
title: Compile-time logging source generation
description: Learn how to use the LoggerMessageAttribute and compile-time source generation for logging in .NET.
author: maryamariyan
ms.author: maariyan
ms.date: 03/13/2023
ms.date: 10/11/2023
---

# Compile-time logging source generation
Expand All @@ -22,7 +20,7 @@ public static partial class Log
[LoggerMessage(
EventId = 0,
Level = LogLevel.Critical,
Message = "Could not open socket to `{hostName}`")]
Message = "Could not open socket to `{HostName}`")]
public static partial void CouldNotOpenSocket(
ILogger logger, string hostName);
}
Expand All @@ -36,7 +34,7 @@ public static partial class Log
[LoggerMessage(
EventId = 0,
Level = LogLevel.Critical,
Message = "Could not open socket to `{hostName}`")]
Message = "Could not open socket to `{HostName}`")]
public static partial void CouldNotOpenSocket(
this ILogger logger, string hostName);
}
Expand All @@ -57,7 +55,7 @@ public partial class InstanceLoggingExample
[LoggerMessage(
EventId = 0,
Level = LogLevel.Critical,
Message = "Could not open socket to `{hostName}`")]
Message = "Could not open socket to `{HostName}`")]
public partial void CouldNotOpenSocket(string hostName);
}
```
Expand All @@ -69,7 +67,7 @@ public static partial class Log
{
[LoggerMessage(
EventId = 0,
Message = "Could not open socket to `{hostName}`")]
Message = "Could not open socket to `{HostName}`")]
public static partial void CouldNotOpenSocket(
ILogger logger,
LogLevel level, /* Dynamic log level as parameter, rather than defined in attribute. */
Expand All @@ -93,7 +91,7 @@ Consider the example logging output when using the `JsonConsole` formatter.
"Message": "Liana lives in Seattle.",
"name": "Liana",
"city": "Seattle",
"{OriginalFormat}": "{name} lives in {city}."
"{OriginalFormat}": "{Name} lives in {City}."
}
}
```
Expand Down Expand Up @@ -140,7 +138,7 @@ As a general rule, the first instance of `ILogger`, `LogLevel`, and `Exception`
```csharp
// This is a valid attribute usage
[LoggerMessage(
EventId = 110, Level = LogLevel.Debug, Message = "M1 {ex3} {ex2}")]
EventId = 110, Level = LogLevel.Debug, Message = "M1 {Ex3} {Ex2}")]
public static partial void ValidLogMethod(
ILogger logger,
Exception ex,
Expand All @@ -149,7 +147,7 @@ public static partial void ValidLogMethod(

// This causes a warning
[LoggerMessage(
EventId = 0, Level = LogLevel.Debug, Message = "M1 {ex} {ex2}")]
EventId = 0, Level = LogLevel.Debug, Message = "M1 {Ex} {Ex2}")]
public static partial void WarningLogMethod(
ILogger logger,
Exception ex,
Expand Down Expand Up @@ -216,7 +214,7 @@ There are no constraints on the ordering of log method parameters. A developer c
[LoggerMessage(
EventId = 110,
Level = LogLevel.Debug,
Message = "M1 {ex3} {ex2}")]
Message = "M1 {Ex3} {Ex2}")]
static partial void LogMethod(
Exception ex,
Exception ex2,
Expand All @@ -237,7 +235,7 @@ static partial void LogMethod(
> "Message": "M1 System.Exception: Third time's the charm. System.Exception: This is the second error.",
> "ex2": "System.Exception: This is the second error.",
> "ex3": "System.Exception: Third time's the charm.",
> "{OriginalFormat}": "M1 {ex3} {ex2}"
> "{OriginalFormat}": "M1 {Ex3} {Ex2}"
> }
> }
> ```
Expand All @@ -263,7 +261,7 @@ public partial class LoggingSample
[LoggerMessage(
EventId = 20,
Level = LogLevel.Critical,
Message = "Value is {value:E}")]
Message = "Value is {Value:E}")]
public static partial void UsingFormatSpecifier(
ILogger logger, double value);

Expand All @@ -276,7 +274,7 @@ public partial class LoggingSample

[LoggerMessage(
EventId = 10,
Message = "Welcome to {city} {province}!")]
Message = "Welcome to {City} {Province}!")]
public partial void LogWithDynamicLogLevel(
string city, LogLevel level, string province);

Expand Down Expand Up @@ -327,7 +325,7 @@ Consider the example logging output when using the `JsonConsole` formatter:
"Message": "Welcome to Vancouver BC!",
"city": "Vancouver",
"province": "BC",
"{OriginalFormat}": "Welcome to {city} {province}!"
"{OriginalFormat}": "Welcome to {City} {Province}!"
}
}
{
Expand All @@ -339,7 +337,7 @@ Consider the example logging output when using the `JsonConsole` formatter:
"Message": "Welcome to Vancouver BC!",
"city": "Vancouver",
"province": "BC",
"{OriginalFormat}": "Welcome to {city} {province}!"
"{OriginalFormat}": "Welcome to {City} {Province}!"
}
}
{
Expand All @@ -350,7 +348,7 @@ Consider the example logging output when using the `JsonConsole` formatter:
"State": {
"Message": "Value is 1.234568E+004",
"value": 12345.6789,
"{OriginalFormat}": "Value is {value:E}"
"{OriginalFormat}": "Value is {Value:E}"
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions docs/core/extensions/logging-library-authors.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Logging guidance for .NET library authors
author: IEvangelist
description: Learn how to expose logging as a library author in .NET. Follow the guidance to ensure your library is correctly exposed to consumers.
ms.author: dapine
ms.date: 08/08/2023
ms.date: 10/11/2023
---

# Logging guidance for .NET library authors
Expand Down Expand Up @@ -49,7 +49,7 @@ namespace Logging.LibraryAuthors;
internal static partial class LogMessages
{
[LoggerMessage(
Message = "Sold {quantity} of {description}",
Message = "Sold {Quantity} of {Description}",
Level = LogLevel.Information,
SkipEnabledCheck = true)]
internal static partial void LogProductSaleDetails(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Logging.LibraryAuthors;
internal static partial class LogMessages
{
[LoggerMessage(
Message = "Sold {quantity} of {description}",
Message = "Sold {Quantity} of {Description}",
Level = LogLevel.Information)]
internal static partial void LogProductSaleDetails(
this ILogger logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ readonly file record struct SampleObject { }

public static partial class Log
{
[LoggerMessage(EventId = 23, Message = "{name} lives in {city}.")]
[LoggerMessage(EventId = 23, Message = "{Name} lives in {City}.")]
public static partial void PlaceOfResidence(
this ILogger logger,
LogLevel logLevel,
Expand Down