diff --git a/bff/samples/Apis/Api.DPoP/Api.DPoP.csproj b/bff/samples/Apis/Api.DPoP/Api.DPoP.csproj index 2883f6494..b6b74ea47 100644 --- a/bff/samples/Apis/Api.DPoP/Api.DPoP.csproj +++ b/bff/samples/Apis/Api.DPoP/Api.DPoP.csproj @@ -7,7 +7,6 @@ - diff --git a/bff/samples/Apis/Api.DPoP/Extensions.cs b/bff/samples/Apis/Api.DPoP/Extensions.cs index 7facfdb4a..035a84cd4 100644 --- a/bff/samples/Apis/Api.DPoP/Extensions.cs +++ b/bff/samples/Apis/Api.DPoP/Extensions.cs @@ -5,7 +5,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.IdentityModel.Tokens; -using Serilog; namespace Api.DPoP; @@ -68,7 +67,7 @@ public static WebApplication ConfigurePipeline(this WebApplication app) // ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto | ForwardedHeaders.XForwardedHost, // }); - app.UseSerilogRequestLogging(); + app.UseHttpLogging(); if (app.Environment.IsDevelopment()) { diff --git a/bff/samples/Apis/Api.DPoP/Program.cs b/bff/samples/Apis/Api.DPoP/Program.cs index 1f9c81d9c..0a8e07be9 100644 --- a/bff/samples/Apis/Api.DPoP/Program.cs +++ b/bff/samples/Apis/Api.DPoP/Program.cs @@ -2,44 +2,14 @@ using Api.DPoP; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Hosting; -using Serilog; -using Serilog.Events; Console.Title = "DPoP Api"; -Log.Logger = new LoggerConfiguration() - .WriteTo.Console() - .CreateBootstrapLogger(); +var builder = WebApplication.CreateBuilder(args); +builder.AddServiceDefaults(); -Log.Information("Starting up"); +var app = builder + .ConfigureServices() + .ConfigurePipeline(); -try -{ - var builder = WebApplication.CreateBuilder(args); - builder.AddServiceDefaults(); - - builder.Host.UseSerilog((ctx, lc) => lc - .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}") - .Enrich.FromLogContext() - .MinimumLevel.Debug() - .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) - .MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information) - .MinimumLevel.Override("System", LogEventLevel.Warning) - .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information) - .ReadFrom.Configuration(ctx.Configuration)); - - var app = builder - .ConfigureServices() - .ConfigurePipeline(); - - app.Run(); -} -catch (Exception ex) -{ - Log.Fatal(ex, "Unhandled exception"); -} -finally -{ - Log.Information("Shut down complete"); - Log.CloseAndFlush(); -} \ No newline at end of file +app.Run(); diff --git a/bff/samples/Apis/Api.Isolated/Api.Isolated.csproj b/bff/samples/Apis/Api.Isolated/Api.Isolated.csproj index b2509050d..9b6aa0db0 100644 --- a/bff/samples/Apis/Api.Isolated/Api.Isolated.csproj +++ b/bff/samples/Apis/Api.Isolated/Api.Isolated.csproj @@ -7,7 +7,6 @@ - diff --git a/bff/samples/Apis/Api.Isolated/Extensions.cs b/bff/samples/Apis/Api.Isolated/Extensions.cs index 0dc3eb205..2ae7cbe2d 100644 --- a/bff/samples/Apis/Api.Isolated/Extensions.cs +++ b/bff/samples/Apis/Api.Isolated/Extensions.cs @@ -6,7 +6,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.IdentityModel.Tokens; -using Serilog; namespace Api.Isolated { @@ -56,7 +55,7 @@ public static WebApplication ConfigurePipeline(this WebApplication app) ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto | ForwardedHeaders.XForwardedHost, }); - app.UseSerilogRequestLogging(); + app.UseHttpLogging(); if (app.Environment.IsDevelopment()) { diff --git a/bff/samples/Apis/Api.Isolated/Program.cs b/bff/samples/Apis/Api.Isolated/Program.cs index c5929d875..3cbd04f92 100644 --- a/bff/samples/Apis/Api.Isolated/Program.cs +++ b/bff/samples/Apis/Api.Isolated/Program.cs @@ -2,44 +2,14 @@ using Api.Isolated; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Hosting; -using Serilog; -using Serilog.Events; Console.Title = "Isolated Api"; -Log.Logger = new LoggerConfiguration() - .WriteTo.Console() - .CreateBootstrapLogger(); +var builder = WebApplication.CreateBuilder(args); +builder.AddServiceDefaults(); -Log.Information("Starting up"); +var app = builder + .ConfigureServices() + .ConfigurePipeline(); -try -{ - var builder = WebApplication.CreateBuilder(args); - builder.AddServiceDefaults(); - - builder.Host.UseSerilog((ctx, lc) => lc - .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}") - .Enrich.FromLogContext() - .MinimumLevel.Debug() - .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) - .MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information) - .MinimumLevel.Override("System", LogEventLevel.Warning) - .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information) - .ReadFrom.Configuration(ctx.Configuration)); - - var app = builder - .ConfigureServices() - .ConfigurePipeline(); - - app.Run(); -} -catch (Exception ex) -{ - Log.Fatal(ex, "Unhandled exception"); -} -finally -{ - Log.Information("Shut down complete"); - Log.CloseAndFlush(); -} \ No newline at end of file +app.Run(); diff --git a/bff/samples/Apis/Api/Api.csproj b/bff/samples/Apis/Api/Api.csproj index 2a3759d6f..9b6aa0db0 100644 --- a/bff/samples/Apis/Api/Api.csproj +++ b/bff/samples/Apis/Api/Api.csproj @@ -1,4 +1,4 @@ - + net9.0 @@ -7,7 +7,6 @@ - diff --git a/bff/samples/Apis/Api/Extensions.cs b/bff/samples/Apis/Api/Extensions.cs index fe7d8a258..bbe269e93 100644 --- a/bff/samples/Apis/Api/Extensions.cs +++ b/bff/samples/Apis/Api/Extensions.cs @@ -6,7 +6,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.IdentityModel.Tokens; -using Serilog; namespace Api; @@ -57,7 +56,7 @@ public static WebApplication ConfigurePipeline(this WebApplication app) ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto | ForwardedHeaders.XForwardedHost, }); - app.UseSerilogRequestLogging(); + app.UseHttpLogging(); if (app.Environment.IsDevelopment()) { diff --git a/bff/samples/Apis/Api/Program.cs b/bff/samples/Apis/Api/Program.cs index 32f8c1f4c..f2293abfd 100644 --- a/bff/samples/Apis/Api/Program.cs +++ b/bff/samples/Apis/Api/Program.cs @@ -1,45 +1,12 @@ -using System; using Api; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Hosting; -using Serilog; -using Serilog.Events; +var builder = WebApplication.CreateBuilder(args); -Console.Title = "Api"; +builder.AddServiceDefaults(); -Log.Logger = new LoggerConfiguration() - .WriteTo.Console() - .CreateBootstrapLogger(); +var app = builder + .ConfigureServices() + .ConfigurePipeline(); -Log.Information("Starting up"); - -try -{ - var builder = WebApplication.CreateBuilder(args); - builder.AddServiceDefaults(); - - builder.Host.UseSerilog((ctx, lc) => lc - .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}") - .Enrich.FromLogContext() - .MinimumLevel.Debug() - .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) - .MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information) - .MinimumLevel.Override("System", LogEventLevel.Warning) - .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information) - .ReadFrom.Configuration(ctx.Configuration)); - - var app = builder - .ConfigureServices() - .ConfigurePipeline(); - - app.Run(); -} -catch (Exception ex) -{ - Log.Fatal(ex, "Unhandled exception"); -} -finally -{ - Log.Information("Shut down complete"); - Log.CloseAndFlush(); -} \ No newline at end of file +app.Run(); diff --git a/bff/samples/Bff.DPoP/Bff.DPoP.csproj b/bff/samples/Bff.DPoP/Bff.DPoP.csproj index 830646dd9..ac5616895 100644 --- a/bff/samples/Bff.DPoP/Bff.DPoP.csproj +++ b/bff/samples/Bff.DPoP/Bff.DPoP.csproj @@ -7,8 +7,7 @@ - - + diff --git a/bff/samples/Bff.DPoP/Extensions.cs b/bff/samples/Bff.DPoP/Extensions.cs index d4ac1cab6..0a67d9fb0 100644 --- a/bff/samples/Bff.DPoP/Extensions.cs +++ b/bff/samples/Bff.DPoP/Extensions.cs @@ -12,10 +12,8 @@ using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; using Microsoft.IdentityModel.Tokens; -using Serilog; using Yarp.ReverseProxy.Configuration; - namespace Bff.DPoP; internal static class Extensions @@ -152,7 +150,7 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde public static WebApplication ConfigurePipeline(this WebApplication app) { - app.UseSerilogRequestLogging(); + app.UseHttpLogging(); app.UseDeveloperExceptionPage(); app.UseDefaultFiles(); diff --git a/bff/samples/Bff.DPoP/Program.cs b/bff/samples/Bff.DPoP/Program.cs index 6b8e049ef..1a0609daf 100644 --- a/bff/samples/Bff.DPoP/Program.cs +++ b/bff/samples/Bff.DPoP/Program.cs @@ -2,44 +2,14 @@ using Bff.DPoP; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Hosting; -using Serilog; -using Serilog.Events; Console.Title = "BFF.DPoP"; -Log.Logger = new LoggerConfiguration() - .WriteTo.Console() - .CreateBootstrapLogger(); +var builder = WebApplication.CreateBuilder(args); +builder.AddServiceDefaults(); -Log.Information("Starting up"); +var app = builder + .ConfigureServices() + .ConfigurePipeline(); -try -{ - var builder = WebApplication.CreateBuilder(args); - builder.AddServiceDefaults(); - - builder.Host.UseSerilog((ctx, lc) => lc - .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}") - .Enrich.FromLogContext() - .MinimumLevel.Debug() - .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) - .MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information) - .MinimumLevel.Override("System", LogEventLevel.Warning) - .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information) - .ReadFrom.Configuration(ctx.Configuration)); - - var app = builder - .ConfigureServices() - .ConfigurePipeline(); - - app.Run(); -} -catch (Exception ex) -{ - Log.Fatal(ex, "Unhandled exception"); -} -finally -{ - Log.Information("Shut down complete"); - Log.CloseAndFlush(); -} \ No newline at end of file +app.Run(); diff --git a/bff/samples/Bff.EF/Bff.EF.csproj b/bff/samples/Bff.EF/Bff.EF.csproj index 780f41f3e..3df6b0b57 100644 --- a/bff/samples/Bff.EF/Bff.EF.csproj +++ b/bff/samples/Bff.EF/Bff.EF.csproj @@ -9,7 +9,6 @@ - diff --git a/bff/samples/Bff.EF/Extensions.cs b/bff/samples/Bff.EF/Extensions.cs index a66e9cff2..43152e913 100644 --- a/bff/samples/Bff.EF/Extensions.cs +++ b/bff/samples/Bff.EF/Extensions.cs @@ -6,14 +6,12 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Serilog; using UserSessionDb.Migrations.UserSessions; namespace Bff.EF { internal static class Extensions { - public static WebApplication ConfigureServices(this WebApplicationBuilder builder) { var services = builder.Services; @@ -79,7 +77,7 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde public static WebApplication ConfigurePipeline(this WebApplication app) { - app.UseSerilogRequestLogging(); + app.UseHttpLogging(); app.UseDeveloperExceptionPage(); app.UseDefaultFiles(); diff --git a/bff/samples/Bff.EF/Program.cs b/bff/samples/Bff.EF/Program.cs index ffc0a83e2..4133416e5 100644 --- a/bff/samples/Bff.EF/Program.cs +++ b/bff/samples/Bff.EF/Program.cs @@ -2,43 +2,14 @@ using Bff.EF; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Hosting; -using Serilog; -using Serilog.Events; Console.Title = "Bff.EF"; -Log.Logger = new LoggerConfiguration() - .WriteTo.Console() - .CreateBootstrapLogger(); +var builder = WebApplication.CreateBuilder(args); +builder.AddServiceDefaults(); -Log.Information("Starting up"); +var app = builder + .ConfigureServices() + .ConfigurePipeline(); -try -{ - var builder = WebApplication.CreateBuilder(args); - builder.AddServiceDefaults(); - builder.Host.UseSerilog((ctx, lc) => lc - .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}") - .Enrich.FromLogContext() - .MinimumLevel.Debug() - .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) - .MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information) - .MinimumLevel.Override("System", LogEventLevel.Warning) - .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information) - .ReadFrom.Configuration(ctx.Configuration)); - - var app = builder - .ConfigureServices() - .ConfigurePipeline(); - - app.Run(); -} -catch (Exception ex) -{ - Log.Fatal(ex, "Unhandled exception"); -} -finally -{ - Log.Information("Shut down complete"); - Log.CloseAndFlush(); -} +app.Run(); diff --git a/bff/samples/Bff/Bff.csproj b/bff/samples/Bff/Bff.csproj index 9e8d5e1cf..73ef15fda 100644 --- a/bff/samples/Bff/Bff.csproj +++ b/bff/samples/Bff/Bff.csproj @@ -1,4 +1,4 @@ - + net9.0 @@ -6,10 +6,6 @@ enable - - - - diff --git a/bff/samples/Bff/Extensions.cs b/bff/samples/Bff/Extensions.cs index 11dffe534..5ec23faf1 100644 --- a/bff/samples/Bff/Extensions.cs +++ b/bff/samples/Bff/Extensions.cs @@ -10,7 +10,6 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.ServiceDiscovery; -using Serilog; namespace Bff; @@ -103,7 +102,7 @@ private static string DiscoverAuthorityByName(Func getServiceP public static WebApplication ConfigurePipeline(this WebApplication app) { - app.UseSerilogRequestLogging(); + app.UseHttpLogging(); app.UseDeveloperExceptionPage(); app.UseDefaultFiles(); diff --git a/bff/samples/Bff/Program.cs b/bff/samples/Bff/Program.cs index 414af53ff..6d93a8452 100644 --- a/bff/samples/Bff/Program.cs +++ b/bff/samples/Bff/Program.cs @@ -2,59 +2,18 @@ using Bff; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Hosting; -using Serilog; -using Serilog.Events; Console.Title = "BFF"; -Log.Logger = new LoggerConfiguration() - .WriteTo.Console() - .CreateBootstrapLogger(); +var builder = WebApplication.CreateBuilder(args); +builder.AddServiceDefaults(); -Log.Information("Starting up"); +var serviceProviderAccessor = new ServiceProviderAccessor(); -try -{ - var builder = WebApplication.CreateBuilder(args); - builder.AddServiceDefaults(); +var app = builder + .ConfigureServices(() => serviceProviderAccessor.ServiceProvider ?? throw new InvalidOperationException("Service Provider must be set")) + .ConfigurePipeline(); - builder.Host.UseSerilog((ctx, lc) => lc - .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}") - .Enrich.FromLogContext() - .MinimumLevel.Debug() - .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) - .MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information) - .MinimumLevel.Override("System", LogEventLevel.Warning) - .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information) - .ReadFrom.Configuration(ctx.Configuration)); +serviceProviderAccessor.ServiceProvider = app.Services; - var serviceProviderAccessor = new ServiceProviderAccessor(); - - var app = builder - .ConfigureServices(() => serviceProviderAccessor.ServiceProvider ?? throw new InvalidOperationException("Service Provider must be set")) - .ConfigurePipeline(); - - serviceProviderAccessor.ServiceProvider = app.Services; - - app.Run(); - - -} -catch (Exception ex) -{ - Log.Fatal(ex, "Unhandled exception"); -} -finally -{ - Log.Information("Shut down complete"); - Log.CloseAndFlush(); -} - -/// -/// A workaround to get the service provider available in the ConfigureServices method -/// -class ServiceProviderAccessor -{ - public IServiceProvider? ServiceProvider { get; set; } - -} +app.Run(); \ No newline at end of file diff --git a/bff/samples/Bff/ServiceProviderAccessor.cs b/bff/samples/Bff/ServiceProviderAccessor.cs new file mode 100644 index 000000000..2fa3fcee0 --- /dev/null +++ b/bff/samples/Bff/ServiceProviderAccessor.cs @@ -0,0 +1,15 @@ +// // Copyright (c) Duende Software. All rights reserved. +// // See LICENSE in the project root for license information. + +using System; + +namespace Bff; + +/// +/// A workaround to get the service provider available in the ConfigureServices method +/// +internal class ServiceProviderAccessor +{ + public IServiceProvider? ServiceProvider { get; set; } + +} \ No newline at end of file diff --git a/bff/samples/Blazor/PerComponent/PerComponent/PerComponent.csproj b/bff/samples/Blazor/PerComponent/PerComponent/PerComponent.csproj index 95a615e69..73b590ebd 100644 --- a/bff/samples/Blazor/PerComponent/PerComponent/PerComponent.csproj +++ b/bff/samples/Blazor/PerComponent/PerComponent/PerComponent.csproj @@ -1,4 +1,4 @@ - + net9.0 @@ -11,6 +11,7 @@ + diff --git a/bff/samples/Blazor/PerComponent/PerComponent/Program.cs b/bff/samples/Blazor/PerComponent/PerComponent/Program.cs index 24fcb6aa3..c936c6ed6 100644 --- a/bff/samples/Blazor/PerComponent/PerComponent/Program.cs +++ b/bff/samples/Blazor/PerComponent/PerComponent/Program.cs @@ -7,14 +7,19 @@ var builder = WebApplication.CreateBuilder(args); +builder.AddServiceDefaults(); + // BFF setup for blazor builder.Services.AddBff() .AddServerSideSessions() .AddBlazorServer() .AddRemoteApis(); + builder.Services.AddUserAccessTokenHttpClient("callApi", configureClient: client => client.BaseAddress = new Uri("https://localhost:5010/")); + + // General blazor services builder.Services.AddRazorComponents() .AddInteractiveServerComponents() @@ -62,6 +67,8 @@ var app = builder.Build(); +app.UseHttpLogging(); + // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { diff --git a/bff/samples/Blazor/WebAssembly/WebAssembly/Program.cs b/bff/samples/Blazor/WebAssembly/WebAssembly/Program.cs index 80d75a87b..ba2aac561 100644 --- a/bff/samples/Blazor/WebAssembly/WebAssembly/Program.cs +++ b/bff/samples/Blazor/WebAssembly/WebAssembly/Program.cs @@ -5,6 +5,8 @@ var builder = WebApplication.CreateBuilder(args); +builder.AddServiceDefaults(); + builder.Services.AddRazorComponents() .AddInteractiveWebAssemblyComponents(); @@ -61,6 +63,8 @@ app.UseHsts(); } +app.UseHttpLogging(); + app.UseHttpsRedirection(); app.UseStaticFiles(); diff --git a/bff/samples/Blazor/WebAssembly/WebAssembly/WebAssembly.csproj b/bff/samples/Blazor/WebAssembly/WebAssembly/WebAssembly.csproj index 6a4527e95..e599b1758 100644 --- a/bff/samples/Blazor/WebAssembly/WebAssembly/WebAssembly.csproj +++ b/bff/samples/Blazor/WebAssembly/WebAssembly/WebAssembly.csproj @@ -8,9 +8,10 @@ + - - + + diff --git a/bff/samples/Hosts.AppHost/Hosts.AppHost.csproj b/bff/samples/Hosts.AppHost/Hosts.AppHost.csproj index 047214201..66ca49dfc 100644 --- a/bff/samples/Hosts.AppHost/Hosts.AppHost.csproj +++ b/bff/samples/Hosts.AppHost/Hosts.AppHost.csproj @@ -12,8 +12,7 @@ - - + diff --git a/bff/samples/Hosts.ServiceDefaults/Extensions.cs b/bff/samples/Hosts.ServiceDefaults/Extensions.cs index fa6c6a2a2..0e2cc4073 100644 --- a/bff/samples/Hosts.ServiceDefaults/Extensions.cs +++ b/bff/samples/Hosts.ServiceDefaults/Extensions.cs @@ -23,6 +23,8 @@ public static TBuilder AddServiceDefaults(this TBuilder builder) where builder.AddDefaultHealthChecks(); + builder.Services.AddHttpLogging(); + builder.Services.AddServiceDiscovery(); builder.Services.ConfigureHttpClientDefaults(http => diff --git a/bff/samples/Hosts.Tests/Hosts.Tests.csproj b/bff/samples/Hosts.Tests/Hosts.Tests.csproj index be9739cca..153ba681f 100644 --- a/bff/samples/Hosts.Tests/Hosts.Tests.csproj +++ b/bff/samples/Hosts.Tests/Hosts.Tests.csproj @@ -1,4 +1,4 @@ - + net9.0 @@ -21,7 +21,10 @@ - + + + + diff --git a/bff/samples/Hosts.Tests/TestInfra/AppHostFixture.cs b/bff/samples/Hosts.Tests/TestInfra/AppHostFixture.cs index 81fbe56d8..bbc2dbac8 100644 --- a/bff/samples/Hosts.Tests/TestInfra/AppHostFixture.cs +++ b/bff/samples/Hosts.Tests/TestInfra/AppHostFixture.cs @@ -92,7 +92,8 @@ await resourceNotificationService.WaitForResourceAsync( .WaitAsync(TimeSpan.FromSeconds(30)); } - +#else + _app = null!; #endif //#DEBUG_NCRUNCH } diff --git a/bff/samples/IdentityServer/Extensions.cs b/bff/samples/IdentityServer/Extensions.cs index 582d6df44..86aba2635 100644 --- a/bff/samples/IdentityServer/Extensions.cs +++ b/bff/samples/IdentityServer/Extensions.cs @@ -2,8 +2,6 @@ // // See LICENSE in the project root for license information. using IdentityServerHost; -using Serilog; - namespace IdentityServer; internal static class Extensions @@ -34,8 +32,8 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde } public static WebApplication ConfigurePipeline(this WebApplication app) - { - app.UseSerilogRequestLogging(); + { + app.UseHttpLogging(); app.UseDeveloperExceptionPage(); app.UseStaticFiles(); diff --git a/bff/samples/IdentityServer/IdentityServer.csproj b/bff/samples/IdentityServer/IdentityServer.csproj index 8bceb8923..00fa1ed7f 100644 --- a/bff/samples/IdentityServer/IdentityServer.csproj +++ b/bff/samples/IdentityServer/IdentityServer.csproj @@ -1,4 +1,4 @@ - + net9.0 @@ -8,7 +8,6 @@ - diff --git a/bff/samples/IdentityServer/Program.cs b/bff/samples/IdentityServer/Program.cs index aba71eda1..fdb4168aa 100644 --- a/bff/samples/IdentityServer/Program.cs +++ b/bff/samples/IdentityServer/Program.cs @@ -1,42 +1,11 @@ -using IdentityServer; -using Serilog; -using Serilog.Events; +using IdentityServer; Console.Title = "IdentityServer"; +var builder = WebApplication.CreateBuilder(args); +builder.AddServiceDefaults(); -Log.Logger = new LoggerConfiguration() - .WriteTo.Console() - .CreateBootstrapLogger(); +var app = builder + .ConfigureServices() + .ConfigurePipeline(); -Log.Information("Starting up"); - -try -{ - var builder = WebApplication.CreateBuilder(args); - builder.AddServiceDefaults(); - - builder.Host.UseSerilog((ctx, lc) => lc - .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}") - .Enrich.FromLogContext() - .MinimumLevel.Debug() - .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) - .MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information) - .MinimumLevel.Override("System", LogEventLevel.Warning) - .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information) - .ReadFrom.Configuration(ctx.Configuration)); - - var app = builder - .ConfigureServices() - .ConfigurePipeline(); - - app.Run(); -} -catch (Exception ex) -{ - Log.Fatal(ex, "Unhandled exception"); -} -finally -{ - Log.Information("Shut down complete"); - Log.CloseAndFlush(); -} \ No newline at end of file +app.Run(); diff --git a/bff/src/Duende.Bff.Blazor.Client/Duende.Bff.Blazor.Client.csproj b/bff/src/Duende.Bff.Blazor.Client/Duende.Bff.Blazor.Client.csproj index 83be62b93..a7f57d418 100644 --- a/bff/src/Duende.Bff.Blazor.Client/Duende.Bff.Blazor.Client.csproj +++ b/bff/src/Duende.Bff.Blazor.Client/Duende.Bff.Blazor.Client.csproj @@ -1,4 +1,4 @@ - + net8.0 diff --git a/bff/test/Duende.Bff.Tests/TestFramework/TestLoggerProvider.cs b/bff/test/Duende.Bff.Tests/TestFramework/TestLoggerProvider.cs index 98ed2f417..9fee91e5b 100644 --- a/bff/test/Duende.Bff.Tests/TestFramework/TestLoggerProvider.cs +++ b/bff/test/Duende.Bff.Tests/TestFramework/TestLoggerProvider.cs @@ -2,8 +2,6 @@ // See LICENSE in the project root for license information. using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; namespace Duende.Bff.Tests.TestFramework { @@ -48,7 +46,14 @@ public void Log(LogLevel logLevel, EventId eventId, TState state, Except private void Log(string msg) { - _writeOutput?.Invoke(_name + msg); + try + { + _writeOutput?.Invoke(_name + msg); + } + catch (Exception) + { + Console.WriteLine("Logging Failed: " + msg); + } LogEntries.Add(msg); } diff --git a/bff/test/Duende.Bff.Tests/TestHosts/BffIntegrationTestBase.cs b/bff/test/Duende.Bff.Tests/TestHosts/BffIntegrationTestBase.cs index db49a7759..45566c2d3 100644 --- a/bff/test/Duende.Bff.Tests/TestHosts/BffIntegrationTestBase.cs +++ b/bff/test/Duende.Bff.Tests/TestHosts/BffIntegrationTestBase.cs @@ -1,33 +1,28 @@ // Copyright (c) Duende Software. All rights reserved. // See LICENSE in the project root for license information. -using System; using Duende.IdentityServer.Models; using Duende.IdentityServer.Services; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using System.Security.Claims; -using System.Threading.Tasks; -using Xunit; using Xunit.Abstractions; namespace Duende.Bff.Tests.TestHosts { - public class BffIntegrationTestBase : IAsyncLifetime + public class BffIntegrationTestBase : OutputWritingTestBase { - private readonly ITestOutputHelper _output; protected readonly IdentityServerHost IdentityServerHost; protected ApiHost ApiHost; protected BffHost BffHost; protected BffHostUsingResourceNamedTokens BffHostWithNamedTokens; - public BffIntegrationTestBase(ITestOutputHelper output) + public BffIntegrationTestBase(ITestOutputHelper output) : base(output) { - _output = output; - IdentityServerHost = new IdentityServerHost(output.WriteLine); - ApiHost = new ApiHost(_output.WriteLine, IdentityServerHost, "scope1"); - BffHost = new BffHost(_output.WriteLine, IdentityServerHost, ApiHost, "spa"); - BffHostWithNamedTokens = new BffHostUsingResourceNamedTokens(_output.WriteLine, IdentityServerHost, ApiHost, "spa"); + IdentityServerHost = new IdentityServerHost(WriteLine); + ApiHost = new ApiHost(WriteLine, IdentityServerHost, "scope1"); + BffHost = new BffHost(WriteLine, IdentityServerHost, ApiHost, "spa"); + BffHostWithNamedTokens = new BffHostUsingResourceNamedTokens(WriteLine, IdentityServerHost, ApiHost, "spa"); IdentityServerHost.Clients.Add(new Client { @@ -59,21 +54,23 @@ public async Task Login(string sub) await IdentityServerHost.IssueSessionCookieAsync(new Claim("sub", sub)); } - public async Task InitializeAsync() + public override async Task InitializeAsync() { await IdentityServerHost.InitializeAsync(); await ApiHost.InitializeAsync(); await BffHost.InitializeAsync(); await BffHostWithNamedTokens.InitializeAsync(); - + await base.InitializeAsync(); } - public async Task DisposeAsync() + public override async Task DisposeAsync() { await ApiHost.DisposeAsync(); await BffHost.DisposeAsync(); await BffHostWithNamedTokens.DisposeAsync(); await IdentityServerHost.DisposeAsync(); + await base.DisposeAsync(); + } } } diff --git a/bff/test/Duende.Bff.Tests/TestHosts/OutputWritingTestBase.cs b/bff/test/Duende.Bff.Tests/TestHosts/OutputWritingTestBase.cs new file mode 100644 index 000000000..c17d46fe8 --- /dev/null +++ b/bff/test/Duende.Bff.Tests/TestHosts/OutputWritingTestBase.cs @@ -0,0 +1,28 @@ +// Copyright (c) Duende Software. All rights reserved. +// See LICENSE in the project root for license information. + +using System.Text; +using Xunit.Abstractions; + +namespace Duende.Bff.Tests.TestHosts; + +public class OutputWritingTestBase(ITestOutputHelper testOutputHelper) : IAsyncLifetime +{ + private readonly StringBuilder _output = new StringBuilder(); + + public void WriteLine(string message) + { + _output.AppendLine(message); + } + + public virtual Task InitializeAsync() + { + return Task.CompletedTask; + } + + public virtual Task DisposeAsync() + { + testOutputHelper.WriteLine(_output.ToString()); + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/bff/test/Duende.Bff.Tests/TestHosts/YarpBffIntegrationTestBase.cs b/bff/test/Duende.Bff.Tests/TestHosts/YarpBffIntegrationTestBase.cs index a0954d2f8..ac03547a7 100644 --- a/bff/test/Duende.Bff.Tests/TestHosts/YarpBffIntegrationTestBase.cs +++ b/bff/test/Duende.Bff.Tests/TestHosts/YarpBffIntegrationTestBase.cs @@ -13,16 +13,16 @@ namespace Duende.Bff.Tests.TestHosts { - public class YarpBffIntegrationTestBase : IAsyncLifetime + public class YarpBffIntegrationTestBase : OutputWritingTestBase { private readonly IdentityServerHost _identityServerHost; protected readonly ApiHost ApiHost; protected readonly YarpBffHost BffHost; private BffHostUsingResourceNamedTokens _bffHostWithNamedTokens; - protected YarpBffIntegrationTestBase(ITestOutputHelper output) + protected YarpBffIntegrationTestBase(ITestOutputHelper output) : base(output) { - _identityServerHost = new IdentityServerHost(output.WriteLine); + _identityServerHost = new IdentityServerHost(WriteLine); _identityServerHost.Clients.Add(new Client { @@ -45,11 +45,11 @@ protected YarpBffIntegrationTestBase(ITestOutputHelper output) provider.GetRequiredService())); }; - ApiHost = new ApiHost(output.WriteLine, _identityServerHost, "scope1"); + ApiHost = new ApiHost(WriteLine, _identityServerHost, "scope1"); - BffHost = new YarpBffHost(output.WriteLine, _identityServerHost, ApiHost, "spa"); + BffHost = new YarpBffHost(WriteLine, _identityServerHost, ApiHost, "spa"); - _bffHostWithNamedTokens = new BffHostUsingResourceNamedTokens(output.WriteLine, _identityServerHost, ApiHost, "spa"); + _bffHostWithNamedTokens = new BffHostUsingResourceNamedTokens(WriteLine, _identityServerHost, ApiHost, "spa"); } public async Task Login(string sub) @@ -57,21 +57,22 @@ public async Task Login(string sub) await _identityServerHost.IssueSessionCookieAsync(new Claim("sub", sub)); } - public async Task InitializeAsync() + public override async Task InitializeAsync() { await _identityServerHost.InitializeAsync(); await ApiHost.InitializeAsync(); await BffHost.InitializeAsync(); await _bffHostWithNamedTokens.InitializeAsync(); - + await base.InitializeAsync(); } - public async Task DisposeAsync() + public override async Task DisposeAsync() { await _identityServerHost.DisposeAsync(); await ApiHost.DisposeAsync(); await BffHost.DisposeAsync(); await _bffHostWithNamedTokens.DisposeAsync(); + await base.DisposeAsync(); } } }