TODO
TODO
TODO
A "scope"
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 for an example.
IncludeFormattedMessage
indicates if the LogRecord.FormattedMessage
will be
set by invoking the formatter from ILogger.Log.
IncludeFormattedMessage
is false
by default.
TODO
Processors
must be added using OpenTelemetryLoggerOptions.AddProcessor()
.
It is not supported to add Processors after building the LoggerFactory
.
var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddOpenTelemetry(options =>
{
options.AddProcessor(...)
});
});
For more information on Processors, please review Extending the SDK
Resource
is the immutable representation of the entity producing the telemetry.
If no Resource
is explicitly configured, the default is to use a resource
indicating this Telemetry
SDK.
The SetResourceBuilder
method on OpenTelemetryLoggerOptions
can be used to
set a single ResourceBuilder
. If SetResourceBuilder
is called multiple
times, only the last is kept. It is not possible to change the resource builder
after creating the LoggerFactory
.
The snippet below shows configuring a custom ResourceBuilder
to the provider.
var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddOpenTelemetry(options =>
{
options.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(
serviceName: "MyService",
serviceVersion: "1.0.0"
));
});
});
See Program.cs for complete example.
It is also possible to configure the Resource
by using following
environmental variables:
Environment variable | Description |
---|---|
OTEL_RESOURCE_ATTRIBUTES |
Key-value pairs to be used as resource attributes. See the Resource SDK specification for more details. |
OTEL_SERVICE_NAME |
Sets the value of the service.name resource attribute. If service.name is also provided in OTEL_RESOURCE_ATTRIBUTES , then OTEL_SERVICE_NAME takes precedence. |
ILogger
implementations have a built-in mechanism to apply log
filtering.
This filtering lets you control the logs that are sent to each registered
provider, including the OpenTelemetryLoggerProvider
. "OpenTelemetry" is the
alias
for OpenTelemetryLoggerProvider
, that may be used in configuring filtering
rules.
The example below defines "Error" as the default LogLevel
and also defines "Warning" as the minimum LogLevel
for a user defined category.
These rules as defined only apply to the OpenTelemetryLoggerProvider
.
ILoggingBuilder.AddFilter<OpenTelemetryLoggerProvider>("*", LogLevel.Error);
ILoggingBuilder.AddFilter<OpenTelemetryLoggerProvider>("category name", LogLevel.Warning);
- See also the official guide for Logging in .NET.