Skip to content

Commit 57a7c1c

Browse files
Merge pull request #218 from AntonioFalcao/feature/evolve-options
Improve dump strategy
2 parents cb175e2 + defe109 commit 57a7c1c

5 files changed

Lines changed: 29 additions & 14 deletions

File tree

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "6.0.100-preview.2.21155.3"
3+
"version": "6.0.100-preview.4.21255.9"
44
}
55
}

src/Dotnet6.GraphQL4.Store.WebAPI/DependencyInjection/Extensions/EndpointRouteBuilderExtensions.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using System;
22
using System.Linq;
3+
using System.Threading.Tasks;
34
using HealthChecks.UI.Client;
45
using Microsoft.AspNetCore.Builder;
56
using Microsoft.AspNetCore.Http;
67
using Microsoft.AspNetCore.Routing;
78
using Microsoft.Extensions.Configuration;
89
using Microsoft.Extensions.Diagnostics.HealthChecks;
10+
using Microsoft.Extensions.Logging;
911

1012
namespace Dotnet6.GraphQL4.Store.WebAPI.DependencyInjection.Extensions
1113
{
@@ -50,16 +52,26 @@ private static void MapHealthChecks(this IEndpointRouteBuilder endpoints, string
5052
}
5153
});
5254

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)
5456
{
55-
if (isProduction) return;
56-
5757
endpoints.MapGet(
58-
pattern: pattern,
58+
pattern: pattern,
5959
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+
}
6375
}
6476
}
6577
}

src/Dotnet6.GraphQL4.Store.WebAPI/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
ARG ASPNET_VERSION="6.0.0-preview.2-alpine3.13"
2-
ARG SDK_VERSION="6.0.100-preview.2-alpine3.13"
1+
ARG ASPNET_VERSION="6.0.0-preview.4-alpine3.13"
2+
ARG SDK_VERSION="6.0.100-preview.4-alpine3.13"
33
ARG BASE_ADRESS="mcr.microsoft.com/dotnet"
44

55
FROM $BASE_ADRESS/aspnet:$ASPNET_VERSION AS base

src/Dotnet6.GraphQL4.Store.WebAPI/Startup.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public void Configure(IApplicationBuilder app , ILoggerFactory loggerFactory)
5050
endpoints.MapDumpConfig(
5151
pattern: "/dump-config",
5252
configurationRoot: _configuration as IConfigurationRoot,
53-
isProduction: _env.IsProduction());
53+
isProduction: _env.IsProduction(),
54+
logger: loggerFactory.CreateLogger<Startup>());
5455

5556
endpoints.MapHealthCheck(
5657
pattern: _configuration["HealthChecksPatterns:Health"]);
@@ -74,8 +75,10 @@ public void ConfigureServices(IServiceCollection services)
7475
services.AddHttpLogging(options
7576
=> options.LoggingFields = HttpLoggingFields.RequestProperties);
7677

78+
services.AddLogging(builder
79+
=> builder.AddSerilog());
80+
7781
services
78-
.AddLogging()
7982
.AddBuilders()
8083
.AddRepositories()
8184
.AddUnitOfWork()

src/Dotnet6.GraphQL4.Store.WebMVC/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
ARG ASPNET_VERSION="6.0.0-preview.2-alpine3.13"
2-
ARG SDK_VERSION="6.0.100-preview.2-alpine3.13"
1+
ARG ASPNET_VERSION="6.0.0-preview.4-alpine3.13"
2+
ARG SDK_VERSION="6.0.100-preview.4-alpine3.13"
33
ARG BASE_ADRESS="mcr.microsoft.com/dotnet"
44

55
FROM $BASE_ADRESS/aspnet:$ASPNET_VERSION AS base

0 commit comments

Comments
 (0)