Log customization doc: IncludeScopes (#3155)

This commit is contained in:
Timothy Mothra 2022-04-12 11:21:03 -07:00 committed by GitHub
parent 9da4ff798a
commit 4cabb23f09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -29,6 +29,7 @@ public class Program
{
builder.AddOpenTelemetry(options =>
{
options.IncludeScopes = true;
options.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(
serviceName: "MyService",
serviceVersion: "1.0.0"));
@ -41,5 +42,12 @@ public class Program
logger.LogInformation("Hello Information");
logger.LogWarning("Hello Warning");
logger.LogError("Hello Error");
// log with scopes
using (logger.BeginScope("operation"))
using (logger.BeginScope("hardware"))
{
logger.LogError("{name} is broken.", "refrigerator");
}
}
}

View File

@ -14,7 +14,15 @@ TODO
### IncludeScopes
TODO
A "[scope](https://docs.microsoft.com/dotnet/core/extensions/logging#log-scopes)"
is an `ILogger` concept that can group a set of logical operations and attach
data to each log created as part of a set.
`IncludeScopes` is off by default. Setting this to `true` will include all
scopes with the exported `LogRecord`. Consult the individual `Exporter`
docs to learn more about how scopes will be processed.
See [Program.cs](Program.cs) for an example.
### IncludeFormattedMessage