You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/operator/logging.mdx
+9-8Lines changed: 9 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,21 +6,21 @@ sidebar_position: 6
6
6
7
7
# Logging, Tracing, and OpenTelemetry
8
8
9
-
## 1. Logging with `ILogger` and Scopes
9
+
## Logging with `ILogger` and Scopes
10
10
11
11
This project uses Microsoft's [`ILogger`](https://learn.microsoft.com/en-us/dotnet/core/extensions/logging) interface for logging. It provides a standardized and extensible way to capture events within the application.
12
12
13
-
Using *scopes* enables hierarchical organization of log messages and allows contextual information to be attached to each entry.
13
+
Using _scopes_ enables hierarchical organization of log messages and allows contextual information to be attached to each entry.
14
14
15
-
### 1.1 ILogger Basics
15
+
### ILogger Basics
16
16
17
17
The `ILogger` interface is part of [`Microsoft.Extensions.Logging`](https://www.nuget.org/packages/Microsoft.Extensions.Logging) and provides methods to log messages at various severity levels (e.g., `Information`, `Warning`, `Error`).
18
18
19
19
Logging can be enabled using either `WebApplication.CreateBuilder`, `Host.CreateDefaultBuilder`, or the `AddLogging` extension method on the `IServiceCollection`.
20
20
21
21
You can log from your code by injecting `ILogger<MyEntityController>` (or a similar type) into your component.
22
22
23
-
### 1.2 Using Scopes
23
+
### Using Scopes
24
24
25
25
Scopes define a logical boundary in which all log entries are automatically enriched with contextual metadata. This is especially useful for correlating logs related to a specific request or operation.
26
26
@@ -78,7 +78,7 @@ To enable scopes with OpenTelemetry, configure it as follows:
78
78
The scope state must be an `IReadOnlyDictionary<string, object?>` to ensure correct serialization and inclusion in log entries.
79
79
:::
80
80
81
-
## 2. Tracing with `System.Diagnostics` and `ActivitySource`
81
+
## Tracing with `System.Diagnostics` and `ActivitySource`
82
82
83
83
For [distributed tracing](https://learn.microsoft.com/en-us/dotnet/core/diagnostics/distributed-tracing-concepts), this project uses `System.Diagnostics` in combination with `ActivitySource`.
84
84
Activities can be started using `ActivitySource.StartActivity`.
## 3. OpenTelemetry Configuration for Azure Logging
116
+
## OpenTelemetry Configuration for Azure Logging
116
117
117
118
To use OpenTelemetry with Azure, it is recommended to adopt the [Azure Monitor OpenTelemetry Distro](https://learn.microsoft.com/en-us/azure/azure-monitor/app/opentelemetry-enable).
118
119
You can enable it via code:
@@ -123,7 +124,7 @@ builder.Services
123
124
.UseAzureMonitor();
124
125
```
125
126
126
-
### 3.2 Full Example Configuration in `Program.cs` (or `Startup.cs`)
127
+
### Full Example Configuration in `Program.cs` (or `Startup.cs`)
127
128
128
129
A complete setup with logging, tracing, and OpenTelemetry might look like this:
0 commit comments