diff --git a/src/Digdir.Domain.Dialogporten.GraphQL/Program.cs b/src/Digdir.Domain.Dialogporten.GraphQL/Program.cs index 8c191dfc3..10040bcad 100644 --- a/src/Digdir.Domain.Dialogporten.GraphQL/Program.cs +++ b/src/Digdir.Domain.Dialogporten.GraphQL/Program.cs @@ -19,17 +19,16 @@ using Microsoft.Extensions.Options; // Using two-stage initialization to catch startup errors. -var telemetryConfiguration = TelemetryConfiguration.CreateDefault(); Log.Logger = new LoggerConfiguration() .MinimumLevel.Warning() .Enrich.FromLogContext() .WriteTo.Console(formatProvider: CultureInfo.InvariantCulture) - .WriteTo.ApplicationInsights(telemetryConfiguration, TelemetryConverter.Traces) + .WriteTo.ApplicationInsights(TelemetryConfiguration.CreateDefault(), TelemetryConverter.Traces) .CreateBootstrapLogger(); try { - BuildAndRun(args, telemetryConfiguration); + BuildAndRun(args); } catch (Exception ex) when (ex is not OperationCanceledException) { @@ -41,7 +40,7 @@ Log.CloseAndFlush(); } -static void BuildAndRun(string[] args, TelemetryConfiguration telemetryConfiguration) +static void BuildAndRun(string[] args) { var builder = WebApplication.CreateBuilder(args); @@ -51,7 +50,7 @@ static void BuildAndRun(string[] args, TelemetryConfiguration telemetryConfigura .ReadFrom.Services(services) .Enrich.FromLogContext() .WriteTo.Console(formatProvider: CultureInfo.InvariantCulture) - .WriteTo.ApplicationInsights(telemetryConfiguration, TelemetryConverter.Traces)); + .WriteTo.ApplicationInsights(services.GetRequiredService(), TelemetryConverter.Traces)); builder.Configuration .AddAzureConfiguration(builder.Environment.EnvironmentName) @@ -77,6 +76,7 @@ static void BuildAndRun(string[] args, TelemetryConfiguration telemetryConfigura .WithPubCapabilities() .Build() .AddAutoMapper(Assembly.GetExecutingAssembly()) + .AddApplicationInsightsTelemetry() .AddScoped() .AddValidatorsFromAssembly(thisAssembly, ServiceLifetime.Transient, includeInternalTypes: true) .AddAzureAppConfiguration()