|
2 | 2 | using Microsoft.Extensions.Configuration; |
3 | 3 | using Microsoft.Extensions.Hosting; |
4 | 4 | using Microsoft.Extensions.Logging; |
| 5 | +using Shared.Logger; |
| 6 | +using Shared.Middleware; |
5 | 7 | using System; |
6 | 8 | using System.Collections.Generic; |
7 | 9 | using System.Linq; |
8 | 10 | using System.Threading.Tasks; |
9 | | -using Shared.Logger; |
10 | | -using Shared.Middleware; |
11 | 11 |
|
12 | 12 | namespace TransactionProcessorACL |
13 | 13 | { |
14 | 14 | using Lamar.Microsoft.DependencyInjection; |
15 | 15 | using NLog; |
16 | 16 | using NLog.Extensions.Logging; |
| 17 | + using Sentry.Extensibility; |
| 18 | + using Shared.General; |
17 | 19 | using System.Diagnostics.CodeAnalysis; |
18 | 20 | using System.IO; |
| 21 | + using System.Reflection; |
19 | 22 |
|
20 | 23 | [ExcludeFromCodeCoverage] |
21 | 24 | public class Program |
@@ -60,6 +63,45 @@ public static IHostBuilder CreateHostBuilder(string[] args) |
60 | 63 | }); |
61 | 64 | hostBuilder.ConfigureWebHostDefaults(webBuilder => |
62 | 65 | { |
| 66 | + webBuilder.ConfigureAppConfiguration((context, configBuilder) => |
| 67 | + { |
| 68 | + var env = context.HostingEnvironment; |
| 69 | + |
| 70 | + configBuilder.SetBasePath(fi.Directory.FullName) |
| 71 | + .AddJsonFile("hosting.json", optional: true) |
| 72 | + .AddJsonFile($"hosting.{env.EnvironmentName}.json", optional: true) |
| 73 | + .AddJsonFile("/home/txnproc/config/appsettings.json", optional: true, reloadOnChange: true) |
| 74 | + .AddJsonFile($"/home/txnproc/config/appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true) |
| 75 | + .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) |
| 76 | + .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true) |
| 77 | + .AddEnvironmentVariables(); |
| 78 | + |
| 79 | + // Build a snapshot of configuration so we can use it immediately (e.g. for Sentry) |
| 80 | + var builtConfig = configBuilder.Build(); |
| 81 | + |
| 82 | + // Keep existing static usage (if you must), and initialise the ConfigurationReader now. |
| 83 | + Startup.Configuration = builtConfig; |
| 84 | + ConfigurationReader.Initialise(Startup.Configuration); |
| 85 | + |
| 86 | + // Configure Sentry on the webBuilder using the config snapshot. |
| 87 | + var sentrySection = builtConfig.GetSection("SentryConfiguration"); |
| 88 | + if (sentrySection.Exists()) |
| 89 | + { |
| 90 | + // Replace the condition below if you intended to only enable Sentry in certain environments. |
| 91 | + if (env.IsDevelopment() == false) |
| 92 | + { |
| 93 | + webBuilder.UseSentry(o => |
| 94 | + { |
| 95 | + o.Dsn = builtConfig["SentryConfiguration:Dsn"]; |
| 96 | + o.SendDefaultPii = true; |
| 97 | + o.MaxRequestBodySize = RequestSize.Always; |
| 98 | + o.CaptureBlockingCalls = true; |
| 99 | + o.Release = Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "unknown"; |
| 100 | + }); |
| 101 | + } |
| 102 | + } |
| 103 | + }); |
| 104 | + |
63 | 105 | webBuilder.UseStartup<Startup>(); |
64 | 106 | webBuilder.UseConfiguration(config); |
65 | 107 | webBuilder.UseKestrel(); |
|
0 commit comments