Skip to content

Commit

Permalink
at long last, fixed my silly bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsPilgaard committed May 6, 2024
1 parent 3c35ba1 commit de1d9d3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'");
Expand All @@ -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;
}
}
}
28 changes: 16 additions & 12 deletions src/shared/Jordnaer.Shared.Infrastructure/SerilogExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<GrafanaLokiOptions>()
Expand All @@ -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);
Expand Down

0 comments on commit de1d9d3

Please sign in to comment.