Replies: 1 comment 4 replies
-
Could you elaborate? I am not sure if I follow the issue. LogRecord.FormattedMessage contains the formatted message as expected. What is missing? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there, I don't know if I miss something in the configuration but when I try to use a log formatter always it's omitted and the output format is a simple string.
This is the example code using a ConsoleExporter:
var serviceName = "Samples.ConsoleExporter";
ActivitySource source;
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddSource(serviceName)
.AddConsoleExporter()
.Build();
if (Activity.Current == null)
{
source = new ActivitySource(serviceName);
}
else
{
source = Activity.Current.Source;
}
using var loggerFactory = LoggerFactory.Create(builder =>
{
builder.ClearProviders();
builder.AddJsonConsole();
builder.AddOpenTelemetry(opt =>
{
opt.AddConsoleExporter();
opt.IncludeFormattedMessage = true;
});
});
using var rootSpan = source.StartActivity("Samples.ConsoleExporter.Handler", ActivityKind.Server);
var logger = loggerFactory.CreateLogger();
logger.LogInformation("Traces are being created and exported");
And the output is:
LogRecord.Timestamp: 2022-12-16T09:20:58.2482340Z
LogRecord.TraceId: 69e3c44e83459b5cbc6d71adb837afea
LogRecord.SpanId: 057c72070fc3bdc1
LogRecord.TraceFlags: Recorded
LogRecord.CategoryName: Program
LogRecord.LogLevel: Information
LogRecord.FormattedMessage: Traces are being created and exported
LogRecord.State (Key:Value):
OriginalFormat (a.k.a Body): Traces are being created and exported
Resource associated with LogRecord:
service.name: unknown_service:dotnet
Activity.TraceId: 69e3c44e83459b5cbc6d71adb837afea
Activity.SpanId: 057c72070fc3bdc1
Activity.TraceFlags: Recorded
Activity.ActivitySourceName: Samples.ConsoleExporter
The expected log format should be:
{"EventId":0,"LogLevel":"Information","Category":"Program","Message":"Traces are being created and exported","State":{"Message":"Traces are being created and exported","{OriginalFormat}":"Traces are being created and exported"}}
Beta Was this translation helpful? Give feedback.
All reactions