-
Notifications
You must be signed in to change notification settings - Fork 6k
Adding process log enricher documentation #49070
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
Open
mariamgerges
wants to merge
22
commits into
main
Choose a base branch
from
mariamaziz/process-enricher-doc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
8ef52af
doc updates
mariamgerges efdcba4
toc update
mariamgerges 502b1fe
fixes
mariamgerges 1ffb580
updates
mariamgerges f96db72
fixing reference
mariamgerges 817295a
fix
mariamgerges 28f4fb0
fixing
mariamgerges d7d9112
added overview and custom enricher
mariamgerges 94315d9
fix
mariamgerges 1a43657
fixes
mariamgerges 165d6c8
fix
mariamgerges e010186
fixing
mariamgerges 26ed855
fix again
mariamgerges 6b00300
adding nuget package reference
mariamgerges c05bb14
custom enricher
mariamgerges 26bcaa8
comments
mariamgerges 72b4f73
rename
mariamgerges cc0f599
fix
mariamgerges 0db22cc
Update custom-enricher.md
IEvangelist 68d667c
updates
mariamgerges 1042b3f
fixing code blocks
mariamgerges 7d8a156
fixing highlights
mariamgerges File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
title: Process log enricher | ||
description: Learn how to use the process log enricher in .NET. | ||
ms.date: 10/10/2025 | ||
--- | ||
|
||
# Process log enricher | ||
|
||
The process enricher augments telemetry logs with process-specific information. | ||
|
||
You can register the enrichers in an IoC container. Then, all registered enrichers are picked up automatically by the respective telemetry instances, such as logs or metrics, where they enrich the telemetry information. | ||
|
||
## Usage | ||
|
||
To be able to use the process log enricher, first you need to enable enrichment like this: | ||
:::code language="csharp" source="snippets/enrichment/Program.cs" highlight="15"::: | ||
|
||
then you can add the <xref:Microsoft.Extensions.DependencyInjection.ProcessEnricherServiceCollectionExtensions.AddProcessLogEnricher*> with default properties, like this: | ||
|
||
:::code language="csharp" source="snippets/enrichment/Program.cs" highlight="16"::: | ||
mariamgerges marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
or alternatively: | ||
|
||
```cs | ||
var hostApplicationBuilder = WebApplication.CreateBuilder(); | ||
hostApplicationBuilder.Services.AddProcessLogEnricher(); | ||
``` | ||
mariamgerges marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Or, optionally, enable or disable individual options of the enricher using <xref:Microsoft.Extensions.DependencyInjection.ProcessEnricherServiceCollectionExtensions.AddProcessLogEnricher(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{Microsoft.Extensions.Diagnostics.Enrichment.ProcessLogEnricherOptions})>: | ||
mariamgerges marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
```cs | ||
serviceCollection.AddProcessLogEnricher(options => | ||
{ | ||
options.ThreadId = true; | ||
options.ProcessId = true; | ||
}); | ||
``` | ||
|
||
You may also disable or enable individual options using `appsettings.json` file configuration, for example: | ||
|
||
```json | ||
{ | ||
"ProcessLogEnricherOptions": { | ||
"ThreadId": true, | ||
"ProcessId": true | ||
} | ||
} | ||
``` | ||
|
||
and apply it accordingly using <xref:Microsoft.Extensions.DependencyInjection.ProcessEnricherServiceCollectionExtensions.AddProcessLogEnricher(Microsoft.Extensions.DependencyInjection.IServiceCollection,Microsoft.Extensions.Configuration.IConfigurationSection)>: | ||
|
||
```cs | ||
serviceCollection.AddProcessLogEnricher(hostBuilder.Configuration.GetSection("ProcessLogEnricherOptions")); | ||
``` | ||
|
||
## Default configuration | ||
|
||
Although default properties are supplied by the process enricher, you can customize them by initializing an instance of <xref:Microsoft.Extensions.Diagnostics.Enrichment.ProcessLogEnricherOptions> and providing it when registering the enricher. | ||
|
||
The default configuration for log enrichment is: | ||
|
||
| Property | Default Value | Description | | ||
| -----------| ----------------|------------------------------------------------------| | ||
| `ProcessId` | true | If true, logs are enriched with the current process ID. | | ||
| `ThreadId` | false | If true, logs are enriched with the current thread ID | |
17 changes: 17 additions & 0 deletions
17
docs/core/enrichment/snippets/enrichment/Enrichment.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.9" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.9" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.9" /> | ||
<PackageReference Include="Microsoft.Extensions.Telemetry" Version="9.9.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) Microsoft Corporation. All Rights Reserved. | ||
|
||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Enrichment | ||
{ | ||
internal static partial class Log | ||
{ | ||
[LoggerMessage(LogLevel.Information, "This is a sample log message")] | ||
public static partial void LogSampleMessage(this ILogger logger); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Text.Json; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Enrichment | ||
{ | ||
internal class Program | ||
{ | ||
public static async Task Main() | ||
{ | ||
var host = new HostBuilder() | ||
.ConfigureLogging((hostingContext, loggingBuilder) => | ||
{ | ||
loggingBuilder.EnableEnrichment(); | ||
loggingBuilder.Services.AddProcessLogEnricher(); | ||
loggingBuilder.AddJsonConsole(op => | ||
{ | ||
op.JsonWriterOptions = new JsonWriterOptions | ||
{ | ||
Indented = true | ||
}; | ||
}); | ||
}); | ||
|
||
var hostBuilder = host.Build(); | ||
var logger = | ||
hostBuilder.Services | ||
.GetRequiredService<ILoggerFactory>() | ||
.CreateLogger<Program>(); | ||
|
||
logger.LogSampleMessage(); | ||
|
||
await hostBuilder.RunAsync(); | ||
|
||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the coding guidelines, this appears to be AI-generated content. The document should include the
ai-usage
frontmatter key with appropriate value (ai-generated or ai-assisted).Copilot generated this review using guidance from repository custom instructions.