This is a duplicate of https://stackoverflow.com/questions/78153592/serilog-open-telemetry-and-azure-app-insights and Matthew Newboult has self-resolved the issue. Thanks for sharing your resolution Matthew Newboult. Sharing the link of the Stack Overflow question here to help other community members who might be looking for answer to similar issue.
net core, open telemetry, serilog and application insights
Matthew Newboult
0
Reputation points
I'm using .net core (8) and have Serilog enabled and am using Open Telemetry to push traces to Azure App Insights. I'm using the correct format in Serilog:
Log.Information("test {@msg}", msg);
All is working but the 'Custom Dimensions' only show the message type and I don't see the structured log. I can serialize the model but that defeats the point of having structured logging in the first place. I've tried all sorts but nothing seems to change this. Here's how I've wired up Open Telemetry and Serilog.
services.AddOpenTelemetry()
.ConfigureResource(builder => ConfigureResource(
builder,
cfg.GetSection("Application:Name").Value ?? "",
cfg.GetSection("Application:Version").Value ?? ""))
.WithTracing(x => x
.AddSource(DiagnosticHeaders.DefaultListenerName)
.AddAzureMonitorTraceExporter(o =>
{
o.ConnectionString = cfg.GetSection("AzureServiceBus:ApplicationInsightsConnectionString").Value;
}))
.WithMetrics(x => x.AddMeter(InstrumentationOptions.MeterName)
.AddAzureMonitorMetricExporter(o =>
{
o.ConnectionString = cfg.GetSection("AzureServiceBus:ApplicationInsightsConnectionString").Value;
}))
.UseAzureMonitor();
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.WriteTo.Console()
.Enrich.WithProperty("ApplicationName", cfg["Application:Name"])
.WriteTo.ApplicationInsights(
cfg["AzureServiceBus:ApplicationInsightsConnectionString"],
new TraceTelemetryConverter())
.CreateLogger();