Skip to content

Commit a09b623

Browse files
authored
Improve the README of console logging example (#4901)
1 parent c03ee85 commit a09b623

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

docs/logs/getting-started-console/README.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,35 @@ Congratulations! You are now collecting logs using OpenTelemetry.
7070

7171
What does the above program do?
7272

73-
The program has a
73+
The program has created a logging pipeline by instantiating a
7474
[`LoggerFactory`](https://docs.microsoft.com/dotnet/api/microsoft.extensions.logging.iloggerfactory)
75-
with OpenTelemetry added as a
76-
[LoggerProvider](https://docs.microsoft.com/dotnet/core/extensions/logging-providers).
77-
This `LoggerFactory` is used to create an
75+
instance, with OpenTelemetry added as a [logging
76+
provider](https://docs.microsoft.com/dotnet/core/extensions/logging-providers).
77+
OpenTelemetry SDK is then configured with a
78+
[ConsoleExporter](../../../src/OpenTelemetry.Exporter.Console/README.md) to
79+
export the logs to the console for demonstration purpose (note: ConsoleExporter
80+
is not intended for production usage, other exporters such as [OTLP
81+
Exporter](../../../src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md)
82+
should be used instead).
83+
84+
The `LoggerFactory` instance is used to create an
7885
[`ILogger`](https://docs.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger)
79-
instance, which is then used to do the logging. [Compile-time logging source
80-
generation](https://docs.microsoft.com/dotnet/core/extensions/logger-message-generator)
81-
is used to achieve structured logging and better performance. The logs are sent to
82-
the `OpenTelemetryLoggerProvider`, which is configured to export logs to
83-
`ConsoleExporter`. `ConsoleExporter` simply displays it on the console.
86+
instance, which is used to do the actual logging.
87+
88+
Following the .NET logging best practice, [compile-time logging source
89+
generation](https://docs.microsoft.com/dotnet/core/extensions/logger-message-generator)
90+
has been used across the example, which delivers high performance, structured
91+
logging, and type-checked parameters:
92+
93+
```csharp
94+
public static partial class ApplicationLogs
95+
{
96+
[LoggerMessage(EventId = 1, Level = LogLevel.Information, Message = "Food `{name}` price changed to `{price}`.")]
97+
public static partial void FoodPriceChanged(this ILogger logger, string name, double price);
98+
99+
...
100+
}
101+
```
84102

85103
> **Note**
86104
> For applications which use `ILogger` with [dependency injection

0 commit comments

Comments
 (0)