Skip to content

Commit ec3b2c7

Browse files
committed
Updated Serilog config for test hosts to direct diagnostic summary to a file
1 parent 2189d8d commit ec3b2c7

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

identity-server/aspire/ServiceDefaults/SerilogExtensions.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.AspNetCore.Builder;
55
using Serilog;
66
using Serilog.Events;
7+
using Serilog.Filters;
78

89
namespace Microsoft.Extensions.Hosting;
910

@@ -21,7 +22,24 @@ public static void ConfigureSerilogDefaults(this WebApplicationBuilder builder)
2122
.MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information)
2223
.MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information)
2324
.MinimumLevel.Override("System", LogEventLevel.Warning)
24-
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}")
25+
.WriteTo.Logger(fileLogger =>
26+
{
27+
fileLogger.WriteTo.File("./diagnostics/diagnostic.log",
28+
rollingInterval: RollingInterval.Day,
29+
fileSizeLimitBytes: 1024 * 1024 * 10, // 10 MB
30+
rollOnFileSizeLimit: true,
31+
outputTemplate:
32+
"[{Timestamp:HH:mm:ss} {Level} {EventId}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}")
33+
.Filter.ByIncludingOnly(Matching.FromSource("Duende.IdentityServer.Licensing.V2.Diagnostics.DiagnosticSummary"));
34+
})
35+
.WriteTo.Logger(consoleLogger =>
36+
{
37+
consoleLogger.WriteTo
38+
.Console(
39+
outputTemplate:
40+
"[{Timestamp:HH:mm:ss} {Level} {EventId}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}")
41+
.Filter.ByExcluding(Matching.FromSource("Duende.IdentityServer.Licensing.V2.Diagnostics.DiagnosticSummary"));
42+
})
2543
.WriteTo.OpenTelemetry(opts =>
2644
{
2745
opts.Endpoint = builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"] ?? "http://localhost:4317";

identity-server/hosts/Configuration/IdentityServerExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ internal static WebApplicationBuilder ConfigureIdentityServer(this WebApplicatio
3030
options.UserInteraction.CreateAccountUrl = "/Account/Create";
3131

3232
options.MutualTls.Enabled = true;
33+
34+
options.Diagnostics.ChunkSize = 1024 * 100 - 32; // 1 MB minus some formatting space;
3335
})
3436
//.AddServerSideSessions()
3537
.AddInMemoryClients([])

identity-server/hosts/EntityFramework-dotnet9/IdentityServerExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ internal static WebApplicationBuilder ConfigureIdentityServer(this WebApplicatio
4949
});
5050

5151
options.MutualTls.Enabled = true;
52+
53+
options.Diagnostics.ChunkSize = 1024 * 100 - 32; // 1 MB minus some formatting space;
5254
})
5355
.AddTestUsers(TestUsers.Users)
5456
// this adds the config data from DB (clients, resources, CORS)

identity-server/hosts/EntityFramework/IdentityServerExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ internal static WebApplicationBuilder ConfigureIdentityServer(this WebApplicatio
4949
});
5050

5151
options.MutualTls.Enabled = true;
52+
53+
options.Diagnostics.ChunkSize = 1024 * 100 - 32; // 1 MB minus some formatting space;
5254
})
5355
.AddTestUsers(TestUsers.Users)
5456
// this adds the config data from DB (clients, resources, CORS)

identity-server/hosts/main/IdentityServerExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,14 @@ internal static WebApplicationBuilder ConfigureIdentityServer(this WebApplicatio
4040
});
4141

4242
options.MutualTls.Enabled = true;
43+
44+
options.Diagnostics.ChunkSize = 1024 * 100 - 32; // 1 MB minus some formatting space;
4345
})
4446
.AddServerSideSessions()
4547
.AddInMemoryClients([.. TestClients.Get()])
4648
.AddInMemoryIdentityResources(TestResources.IdentityResources)
49+
.AddInMemoryApiResources(TestResources.ApiResources)
50+
.AddInMemoryApiScopes(TestResources.ApiScopes)
4751
//.AddStaticSigningCredential()
4852
.AddExtensionGrantValidator<ExtensionGrantValidator>()
4953
.AddExtensionGrantValidator<NoSubjectExtensionGrantValidator>()

0 commit comments

Comments
 (0)