|
1 | 1 | using System; |
2 | 2 | using System.Linq; |
| 3 | +using System.Threading.Tasks; |
3 | 4 | using HealthChecks.UI.Client; |
4 | 5 | using Microsoft.AspNetCore.Builder; |
5 | 6 | using Microsoft.AspNetCore.Http; |
6 | 7 | using Microsoft.AspNetCore.Routing; |
7 | 8 | using Microsoft.Extensions.Configuration; |
8 | 9 | using Microsoft.Extensions.Diagnostics.HealthChecks; |
| 10 | +using Microsoft.Extensions.Logging; |
9 | 11 |
|
10 | 12 | namespace Dotnet6.GraphQL4.Store.WebAPI.DependencyInjection.Extensions |
11 | 13 | { |
@@ -50,16 +52,26 @@ private static void MapHealthChecks(this IEndpointRouteBuilder endpoints, string |
50 | 52 | } |
51 | 53 | }); |
52 | 54 |
|
53 | | - public static void MapDumpConfig(this IEndpointRouteBuilder endpoints, string pattern, IConfigurationRoot configurationRoot, bool isProduction) |
| 55 | + public static void MapDumpConfig(this IEndpointRouteBuilder endpoints, string pattern, IConfigurationRoot configurationRoot, bool isProduction, ILogger logger) |
54 | 56 | { |
55 | | - if (isProduction) return; |
56 | | - |
57 | 57 | endpoints.MapGet( |
58 | | - pattern: pattern, |
| 58 | + pattern: pattern, |
59 | 59 | requestDelegate: context |
60 | | - => context.Response.WriteAsync( |
61 | | - text: configurationRoot.GetDebugView(), |
62 | | - cancellationToken: context.RequestAborted)); |
| 60 | + => isProduction ? DumpToLog(context) : DumpToResponse(context)); |
| 61 | + |
| 62 | + Task DumpToResponse(HttpContext context) |
| 63 | + => context.Response.WriteAsync( |
| 64 | + text: configurationRoot.GetDebugView(), |
| 65 | + cancellationToken: context.RequestAborted); |
| 66 | + |
| 67 | + Task DumpToLog(HttpContext context) |
| 68 | + { |
| 69 | + logger.LogInformation("{Settings}", configurationRoot.GetDebugView()); |
| 70 | + |
| 71 | + return context.Response.WriteAsync( |
| 72 | + text: "Configuration dumped successfully", |
| 73 | + cancellationToken: context.RequestAborted); |
| 74 | + } |
63 | 75 | } |
64 | 76 | } |
65 | 77 | } |
0 commit comments