44
55using Microsoft . AspNetCore . Hosting ;
66using Microsoft . Extensions . Hosting ;
7+ using NLog . Extensions . Logging ;
78using Serilog ;
89using Serilog . Events ;
910using Serilog . Sinks . SystemConsole . Themes ;
10- using System ;
11- using NLog . Extensions . Logging ;
1211using Shared . Logger ;
1312using Shared . Middleware ;
13+ using System ;
14+ using Sentry . Extensibility ;
1415
1516namespace SecurityService
1617{
@@ -23,6 +24,7 @@ namespace SecurityService
2324 using Newtonsoft . Json ;
2425 using Newtonsoft . Json . Serialization ;
2526 using NLog ;
27+ using Shared . General ;
2628 using System . Diagnostics . CodeAnalysis ;
2729 using System . IO ;
2830 using System . Linq ;
@@ -71,6 +73,45 @@ private static void ConfigureWeb(IHostBuilder hostBuilder) {
7173
7274 hostBuilder . ConfigureWebHostDefaults ( webBuilder =>
7375 {
76+ webBuilder . ConfigureAppConfiguration ( ( context , configBuilder ) =>
77+ {
78+ var env = context . HostingEnvironment ;
79+
80+ configBuilder . SetBasePath ( fi . Directory . FullName )
81+ . AddJsonFile ( "hosting.json" , optional : true )
82+ . AddJsonFile ( $ "hosting.{ env . EnvironmentName } .json", optional : true )
83+ . AddJsonFile ( "/home/txnproc/config/appsettings.json" , optional : true , reloadOnChange : true )
84+ . AddJsonFile ( $ "/home/txnproc/config/appsettings.{ env . EnvironmentName } .json", optional : true , reloadOnChange : true )
85+ . AddJsonFile ( "appsettings.json" , optional : true , reloadOnChange : true )
86+ . AddJsonFile ( $ "appsettings.{ env . EnvironmentName } .json", optional : true , reloadOnChange : true )
87+ . AddEnvironmentVariables ( ) ;
88+
89+ // Build a snapshot of configuration so we can use it immediately (e.g. for Sentry)
90+ var builtConfig = configBuilder . Build ( ) ;
91+
92+ // Keep existing static usage (if you must), and initialise the ConfigurationReader now.
93+ Startup . Configuration = builtConfig ;
94+ ConfigurationReader . Initialise ( Startup . Configuration ) ;
95+
96+ // Configure Sentry on the webBuilder using the config snapshot.
97+ var sentrySection = builtConfig . GetSection ( "SentryConfiguration" ) ;
98+ if ( sentrySection . Exists ( ) )
99+ {
100+ // Replace the condition below if you intended to only enable Sentry in certain environments.
101+ if ( env . IsDevelopment ( ) == false )
102+ {
103+ webBuilder . UseSentry ( o =>
104+ {
105+ o . Dsn = builtConfig [ "SentryConfiguration:Dsn" ] ;
106+ o . SendDefaultPii = true ;
107+ o . MaxRequestBodySize = RequestSize . Always ;
108+ o . CaptureBlockingCalls = true ;
109+ o . Release = Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version ? . ToString ( ) ?? "unknown" ;
110+ } ) ;
111+ }
112+ }
113+ } ) ;
114+
74115 webBuilder . UseStartup < Startup > ( ) ;
75116 webBuilder . ConfigureServices ( services =>
76117 {
0 commit comments