Skip to content

Commit

Permalink
chore: adds debug json console flag
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardosbcabral committed Apr 13, 2024
1 parent 3741226 commit 7770da0
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/Scaffolding.AspNetCore/Extensions/HostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static IHostBuilder AddSerilogLogging(
this IHostBuilder builder,
IScaffoldingConfiguration configuration,
string requestKeyHeader = "RequestKey",
bool debugAsConsole = false)
bool debugAsJson = false)
{
return builder.UseSerilog((context, loggerCfg) =>
{
Expand All @@ -46,21 +46,20 @@ public static IHostBuilder AddSerilogLogging(
.Enrich.WithProperty(nameof(applicationSettings.Domain), applicationSettings.Domain)
.Enrich.With(new RemovePropertiesEnricher());

if (context.HostingEnvironment.IsDevelopment() || debugAsConsole)
if (context.HostingEnvironment.IsDevelopment() && !debugAsJson)
{
loggerCfg
.WriteTo.Console()
.WriteTo.Debug();
}
else
{
loggerCfg
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
// Filter out ASP.NET Core infrastructre logs that are Information and below
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
.Destructure.UsingAttributes(x => x.IgnoreNullProperties = true)
.WriteTo.Async(x => x.Console(new SnakeCaseRenderedCompactJsonFormatter()));
.WriteTo.Debug();
return;
}

loggerCfg
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
// Filter out ASP.NET Core infrastructre logs that are Information and below
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
.Destructure.UsingAttributes(x => x.IgnoreNullProperties = true)
.WriteTo.Async(x => x.Console(new SnakeCaseRenderedCompactJsonFormatter()));
});
}
}
Expand Down

0 comments on commit 7770da0

Please sign in to comment.