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);