Skip to content

Commit

Permalink
Use WithLogging in example app.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBlanch committed May 23, 2024
1 parent dc3e25a commit 07501bf
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions examples/AspNetCore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
// for manual instrumentation
appBuilder.Services.AddSingleton<Instrumentation>();

// Configure OpenTelemetry tracing & metrics with auto-start using the
// Clear default logging providers used by WebApplication host.
appBuilder.Logging.ClearProviders();

// Configure OpenTelemetry logging, metrics, & tracing with auto-start using the
// AddOpenTelemetry extension from OpenTelemetry.Extensions.Hosting.
appBuilder.Services.AddOpenTelemetry()
.ConfigureResource(configureResource)
Expand Down Expand Up @@ -121,34 +124,29 @@
builder.AddConsoleExporter();
break;
}
});

// Clear default logging providers used by WebApplication host.
appBuilder.Logging.ClearProviders();

// Configure OpenTelemetry Logging.
appBuilder.Logging.UseOpenTelemetry(builder =>
{
// Note: See appsettings.json Logging:OpenTelemetry section for configuration.
})
.WithLogging(builder =>
{
// Note: See appsettings.json Logging:OpenTelemetry section for configuration.

var resourceBuilder = ResourceBuilder.CreateDefault();
configureResource(resourceBuilder);
builder.SetResourceBuilder(resourceBuilder);
var resourceBuilder = ResourceBuilder.CreateDefault();
configureResource(resourceBuilder);
builder.SetResourceBuilder(resourceBuilder);

switch (logExporter)
{
case "otlp":
builder.AddOtlpExporter(otlpOptions =>
{
// Use IConfiguration directly for Otlp exporter endpoint option.
otlpOptions.Endpoint = new Uri(appBuilder.Configuration.GetValue("Otlp:Endpoint", defaultValue: "http://localhost:4317")!);
});
break;
default:
builder.AddConsoleExporter();
break;
}
});
switch (logExporter)
{
case "otlp":
builder.AddOtlpExporter(otlpOptions =>
{
// Use IConfiguration directly for Otlp exporter endpoint option.
otlpOptions.Endpoint = new Uri(appBuilder.Configuration.GetValue("Otlp:Endpoint", defaultValue: "http://localhost:4317")!);
});
break;
default:
builder.AddConsoleExporter();
break;
}
});

appBuilder.Services.AddControllers();

Expand Down

0 comments on commit 07501bf

Please sign in to comment.