@@ -41,6 +41,18 @@ public static void LoadSettings()
4141 ReadStackifyJSONConfig ( ) ; // TODO: Better way?
4242 }
4343
44+ if ( IsStackifyJsonLoaded == true )
45+ {
46+ StackifyAPILogger . Log ( $ "#Config - LoadSettings - Stackify JSON Loaded") ;
47+ }
48+
49+ #if NETCORE || NETCOREX
50+ if ( _configuration != null )
51+ {
52+ StackifyAPILogger . Log ( $ "#Config - LoadSettings - Configuration Set") ;
53+ }
54+ #endif
55+
4456 CaptureServerVariables = Get ( "Stackify.CaptureServerVariables" , bool . FalseString ) . Equals ( bool . TrueString , StringComparison . CurrentCultureIgnoreCase ) ;
4557
4658 CaptureSessionVariables = Get ( "Stackify.CaptureSessionVariables" , bool . FalseString ) . Equals ( bool . TrueString , StringComparison . CurrentCultureIgnoreCase ) ;
@@ -134,7 +146,7 @@ public static void LoadSettings()
134146 }
135147
136148 var rumKey = Get ( "Stackify.Rum_Key" ) ;
137- if ( Regex . IsMatch ( rumKey , "^[A-Za-z0-9_-]+$" ) )
149+ if ( string . IsNullOrWhiteSpace ( rumKey ) == false && Regex . IsMatch ( rumKey , "^[A-Za-z0-9_-]+$" ) )
138150 {
139151 RumKey = rumKey ;
140152 }
@@ -197,6 +209,7 @@ public static void LoadSettings()
197209 internal static string Get ( string key , string defaultValue = null )
198210 {
199211 string v = null ;
212+ string section = null ;
200213
201214 try
202215 {
@@ -207,55 +220,69 @@ internal static string Get(string key, string defaultValue = null)
207220 {
208221 var appSettings = _configuration . GetSection ( "Stackify" ) ;
209222 v = appSettings [ key . Replace ( "Stackify." , string . Empty ) ] ;
223+ section = "ConfigStackify" ;
210224
211225 //Get settings from Stackify.json
212- if ( string . IsNullOrEmpty ( v ) )
226+ if ( string . IsNullOrWhiteSpace ( v ) )
213227 {
214228 var key2 = key . Replace ( "Stackify." , string . Empty ) ;
215229 var stackifyJson = _configuration . GetSection ( key2 ) ;
216230 v = stackifyJson . Value ;
217- if ( string . IsNullOrEmpty ( v ) )
231+ section = "ConfigDirect" ;
232+
233+ if ( string . IsNullOrWhiteSpace ( v ) )
218234 {
219235 // Search in Retrace, but key will likely still be Stackify.name, not Retrace.name in the code
220236 var retraceAppSettings = _configuration . GetSection ( "Retrace" ) ;
221237 v = retraceAppSettings [ key . Replace ( "Stackify." , string . Empty ) ] ;
238+ section = "ConfigRetrace" ;
222239 }
223240 }
224241 }
225242#endif
226243
227244#if NETFULL
228- if ( string . IsNullOrEmpty ( v ) )
229- {
230- v = System . Configuration . ConfigurationManager . AppSettings [ key ] ;
231- }
245+ if ( string . IsNullOrWhiteSpace ( v ) )
246+ {
247+ v = System . Configuration . ConfigurationManager . AppSettings [ key ] ;
248+ section = "AppSettings" ;
249+ }
232250#endif
233251
234- if ( string . IsNullOrEmpty ( v ) )
235- {
236- v = System . Environment . GetEnvironmentVariable ( key ) ;
237- }
252+ if ( string . IsNullOrWhiteSpace ( v ) )
253+ {
254+ v = System . Environment . GetEnvironmentVariable ( key ) ;
255+ section = "Env" ;
256+ }
238257
239- if ( string . IsNullOrEmpty ( v ) )
240- {
241- v = System . Environment . GetEnvironmentVariable ( key . ToUpperInvariant ( ) ) ;
242- }
258+ if ( string . IsNullOrWhiteSpace ( v ) )
259+ {
260+ v = System . Environment . GetEnvironmentVariable ( key . ToUpperInvariant ( ) ) ;
261+ section = "EnvUpper" ;
262+ }
243263
244- if ( string . IsNullOrEmpty ( v ) )
245- {
246- // Linux systems do not allow period in an environment variable name
247- v = System . Environment . GetEnvironmentVariable ( key . Replace ( '.' , '_' ) . ToUpperInvariant ( ) ) ;
248- }
264+ if ( string . IsNullOrWhiteSpace ( v ) )
265+ {
266+ // Linux systems do not allow period in an environment variable name
267+ v = System . Environment . GetEnvironmentVariable ( key . Replace ( '.' , '_' ) . ToUpperInvariant ( ) ) ;
268+ section = "EnvUpperLinux" ;
269+ }
249270
250- if ( string . IsNullOrEmpty ( v ) && key . StartsWith ( "Stackify." ) )
251- {
252- v = System . Environment . GetEnvironmentVariable ( "RETRACE_" + key . Substring ( 9 ) . Replace ( '.' , '_' ) . ToUpperInvariant ( ) ) ;
253- }
271+ if ( string . IsNullOrWhiteSpace ( v ) && key . StartsWith ( "Stackify." ) )
272+ {
273+ v = System . Environment . GetEnvironmentVariable ( "RETRACE_" + key . Substring ( 9 ) . Replace ( '.' , '_' ) . ToUpperInvariant ( ) ) ;
274+ section = "EnvUpperLinuxRetrace" ;
275+ }
276+
277+ if ( string . IsNullOrWhiteSpace ( v ) == false )
278+ {
279+ StackifyAPILogger . Log ( $ "#Config - #Get - Section: { section } - Key: { key } - Value: { v ?? "Empty" } ") ;
280+ }
254281 }
255282 }
256- catch ( Exception ex )
283+ catch ( Exception ex )
257284 {
258- StackifyAPILogger . Log ( "#Config #Get failed " , ex ) ;
285+ StackifyAPILogger . Log ( "#Config - #Get - #Failed " , ex ) ;
259286 }
260287 finally
261288 {
@@ -272,19 +299,17 @@ public static void ReadStackifyJSONConfig()
272299 {
273300 try
274301 {
275- var ASPEnvironment = System . Environment . GetEnvironmentVariable ( "ASPNETCORE_ENVIRONMENT" ) ;
302+ var ASPEnvironment = System . Environment . GetEnvironmentVariable ( "ASPNETCORE_ENVIRONMENT" ) ?? "Production" ;
276303 var DotnetEnvironment = System . Environment . GetEnvironmentVariable ( "DOTNET_ENVIRONMENT" ) ;
277304 string baseDirectory = Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) ;
278305 string jsonPath = string . Empty ;
279306 string json = string . Empty ;
280307
281- ASPEnvironment = "Production" ;
282-
283- if ( ! String . IsNullOrEmpty ( ASPEnvironment ) )
308+ if ( ! String . IsNullOrWhiteSpace ( ASPEnvironment ) )
284309 {
285310 jsonPath = Path . Combine ( baseDirectory , $ "Stackify.{ ASPEnvironment } .json") ;
286311 }
287- else if ( ! String . IsNullOrEmpty ( DotnetEnvironment ) )
312+ else if ( ! String . IsNullOrWhiteSpace ( DotnetEnvironment ) )
288313 {
289314 jsonPath = Path . Combine ( baseDirectory , $ "Stackify.{ DotnetEnvironment } .json") ;
290315 }
@@ -312,11 +337,11 @@ public static void ReadStackifyJSONConfig()
312337 string iisBaseDirectory = System . Web . Hosting . HostingEnvironment . ApplicationPhysicalPath ;
313338 string iisJsonPath = string . Empty ;
314339
315- if ( ! String . IsNullOrEmpty ( ASPEnvironment ) )
340+ if ( ! String . IsNullOrWhiteSpace ( ASPEnvironment ) )
316341 {
317342 iisJsonPath = Path . Combine ( iisBaseDirectory , $ "Stackify.{ ASPEnvironment } .json") ;
318343 }
319- else if ( ! String . IsNullOrEmpty ( DotnetEnvironment ) )
344+ else if ( ! String . IsNullOrWhiteSpace ( DotnetEnvironment ) )
320345 {
321346 iisJsonPath = Path . Combine ( iisBaseDirectory , $ "Stackify.{ DotnetEnvironment } .json") ;
322347 }
0 commit comments