From de1d9d34c8de2fe9b286b41eab55b5e6433761f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Pilgaard=20Gr=C3=B8ndahl?= Date: Mon, 6 May 2024 20:47:56 +0200 Subject: [PATCH] at long last, fixed my silly bugs --- .../AzureAppConfigurationExtensions.cs | 6 ++-- .../SerilogExtensions.cs | 28 +++++++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/shared/Jordnaer.Shared.Infrastructure/AzureAppConfigurationExtensions.cs b/src/shared/Jordnaer.Shared.Infrastructure/AzureAppConfigurationExtensions.cs index e42c09bf..03e7f8e6 100644 --- a/src/shared/Jordnaer.Shared.Infrastructure/AzureAppConfigurationExtensions.cs +++ b/src/shared/Jordnaer.Shared.Infrastructure/AzureAppConfigurationExtensions.cs @@ -16,8 +16,7 @@ public static WebApplicationBuilder AddAzureAppConfiguration(this WebApplication return builder; } - - var connectionString = builder.Configuration.GetConnectionString("") + var connectionString = builder.Configuration.GetConnectionString("AppConfig") ?? throw new InvalidOperationException( "Failed to find connection string to Azure App Configuration. " + "Keys checked: 'ConnectionStrings:AppConfig'"); @@ -30,9 +29,8 @@ public static WebApplicationBuilder AddAzureAppConfiguration(this WebApplication // Only reload configs if the 'Sentinel' key is modified refreshOptions.Register("Sentinel", refreshAll: true)) .UseFeatureFlags()); - builder.Services.AddAzureAppConfiguration(); return builder; } -} +} \ No newline at end of file diff --git a/src/shared/Jordnaer.Shared.Infrastructure/SerilogExtensions.cs b/src/shared/Jordnaer.Shared.Infrastructure/SerilogExtensions.cs index 4f416b30..cc1a3b36 100644 --- a/src/shared/Jordnaer.Shared.Infrastructure/SerilogExtensions.cs +++ b/src/shared/Jordnaer.Shared.Infrastructure/SerilogExtensions.cs @@ -16,19 +16,8 @@ public static class SerilogExtensions { public static WebApplicationBuilder AddSerilog(this WebApplicationBuilder builder) { - builder.Host.UseSerilog((context, provider, loggerConfiguration) => + if (!builder.Environment.IsDevelopment()) { - loggerConfiguration.ReadFrom.Configuration(context.Configuration) - .Enrich.WithProperty("Application", builder.Environment.ApplicationName) - .Enrich.FromLogContext() - .Enrich.WithExceptionDetails(); - - loggerConfiguration.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss}] [{Level}] {SourceContext}: {Message:lj}{NewLine}{Exception}"); - - if (context.HostingEnvironment.IsDevelopment()) - { - return; - } builder.Services .AddOptions() @@ -41,6 +30,21 @@ public static WebApplicationBuilder AddSerilog(this WebApplicationBuilder builde .BindConfiguration(ElmahIoOptions.SectionName) .ValidateDataAnnotations() .ValidateOnStart(); + } + + builder.Host.UseSerilog((context, provider, loggerConfiguration) => + { + loggerConfiguration.ReadFrom.Configuration(context.Configuration) + .Enrich.WithProperty("Application", builder.Environment.ApplicationName) + .Enrich.FromLogContext() + .Enrich.WithExceptionDetails(); + + loggerConfiguration.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss}] [{Level}] {SourceContext}: {Message:lj}{NewLine}{Exception}"); + + if (context.HostingEnvironment.IsDevelopment()) + { + return; + } loggerConfiguration.WriteToLoki(provider); loggerConfiguration.WriteToElmahIo(provider);