@@ -38,9 +38,22 @@ public static void LoadSettings()
3838 try
3939 {
4040 if ( IsStackifyJsonLoaded == false ) {
41+ StackifyAPILogger . Log ( $ "#Config - LoadSettings - Stackify JSON - Read") ;
4142 ReadStackifyJSONConfig ( ) ; // TODO: Better way?
4243 }
4344
45+ if ( IsStackifyJsonLoaded == true )
46+ {
47+ StackifyAPILogger . Log ( $ "#Config - LoadSettings - Stackify JSON Loaded") ;
48+ }
49+
50+ #if NETCORE || NETCOREX
51+ if ( _configuration != null )
52+ {
53+ StackifyAPILogger . Log ( $ "#Config - LoadSettings - Configuration Set") ;
54+ }
55+ #endif
56+
4457 CaptureServerVariables = Get ( "Stackify.CaptureServerVariables" , bool . FalseString ) . Equals ( bool . TrueString , StringComparison . CurrentCultureIgnoreCase ) ;
4558
4659 CaptureSessionVariables = Get ( "Stackify.CaptureSessionVariables" , bool . FalseString ) . Equals ( bool . TrueString , StringComparison . CurrentCultureIgnoreCase ) ;
@@ -134,7 +147,7 @@ public static void LoadSettings()
134147 }
135148
136149 var rumKey = Get ( "Stackify.Rum_Key" ) ;
137- if ( Regex . IsMatch ( rumKey , "^[A-Za-z0-9_-]+$" ) )
150+ if ( string . IsNullOrWhiteSpace ( rumKey ) == false && Regex . IsMatch ( rumKey , "^[A-Za-z0-9_-]+$" ) )
138151 {
139152 RumKey = rumKey ;
140153 }
@@ -143,6 +156,15 @@ public static void LoadSettings()
143156 {
144157 StackifyAPILogger . Log ( "#Config #LoadSettings failed" , ex ) ;
145158 }
159+
160+ try
161+ {
162+ StackifyAPILogger . EvaluateLogEnabled ( ) ;
163+ }
164+ catch ( Exception ex )
165+ {
166+ StackifyAPILogger . Log ( "#Config #LoadSettings StackifyAPILogger.EvaluateLogEnabled failed" , ex ) ;
167+ }
146168 }
147169
148170 public static string ApiKey { get ; set ; }
@@ -197,6 +219,7 @@ public static void LoadSettings()
197219 internal static string Get ( string key , string defaultValue = null )
198220 {
199221 string v = null ;
222+ string section = null ;
200223
201224 try
202225 {
@@ -207,55 +230,69 @@ internal static string Get(string key, string defaultValue = null)
207230 {
208231 var appSettings = _configuration . GetSection ( "Stackify" ) ;
209232 v = appSettings [ key . Replace ( "Stackify." , string . Empty ) ] ;
233+ section = "ConfigStackify" ;
210234
211235 //Get settings from Stackify.json
212- if ( string . IsNullOrEmpty ( v ) )
236+ if ( string . IsNullOrWhiteSpace ( v ) )
213237 {
214238 var key2 = key . Replace ( "Stackify." , string . Empty ) ;
215239 var stackifyJson = _configuration . GetSection ( key2 ) ;
216240 v = stackifyJson . Value ;
217- if ( string . IsNullOrEmpty ( v ) )
241+ section = "ConfigDirect" ;
242+
243+ if ( string . IsNullOrWhiteSpace ( v ) )
218244 {
219245 // Search in Retrace, but key will likely still be Stackify.name, not Retrace.name in the code
220246 var retraceAppSettings = _configuration . GetSection ( "Retrace" ) ;
221247 v = retraceAppSettings [ key . Replace ( "Stackify." , string . Empty ) ] ;
248+ section = "ConfigRetrace" ;
222249 }
223250 }
224251 }
225252#endif
226253
227254#if NETFULL
228- if ( string . IsNullOrEmpty ( v ) )
229- {
230- v = System . Configuration . ConfigurationManager . AppSettings [ key ] ;
231- }
255+ if ( string . IsNullOrWhiteSpace ( v ) )
256+ {
257+ v = System . Configuration . ConfigurationManager . AppSettings [ key ] ;
258+ section = "AppSettings" ;
259+ }
232260#endif
233261
234- if ( string . IsNullOrEmpty ( v ) )
235- {
236- v = System . Environment . GetEnvironmentVariable ( key ) ;
237- }
262+ if ( string . IsNullOrWhiteSpace ( v ) )
263+ {
264+ v = System . Environment . GetEnvironmentVariable ( key ) ;
265+ section = "Env" ;
266+ }
238267
239- if ( string . IsNullOrEmpty ( v ) )
240- {
241- v = System . Environment . GetEnvironmentVariable ( key . ToUpperInvariant ( ) ) ;
242- }
268+ if ( string . IsNullOrWhiteSpace ( v ) )
269+ {
270+ v = System . Environment . GetEnvironmentVariable ( key . ToUpperInvariant ( ) ) ;
271+ section = "EnvUpper" ;
272+ }
243273
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- }
274+ if ( string . IsNullOrWhiteSpace ( v ) )
275+ {
276+ // Linux systems do not allow period in an environment variable name
277+ v = System . Environment . GetEnvironmentVariable ( key . Replace ( '.' , '_' ) . ToUpperInvariant ( ) ) ;
278+ section = "EnvUpperLinux" ;
279+ }
249280
250- if ( string . IsNullOrEmpty ( v ) && key . StartsWith ( "Stackify." ) )
251- {
252- v = System . Environment . GetEnvironmentVariable ( "RETRACE_" + key . Substring ( 9 ) . Replace ( '.' , '_' ) . ToUpperInvariant ( ) ) ;
253- }
281+ if ( string . IsNullOrWhiteSpace ( v ) && key . StartsWith ( "Stackify." ) )
282+ {
283+ v = System . Environment . GetEnvironmentVariable ( "RETRACE_" + key . Substring ( 9 ) . Replace ( '.' , '_' ) . ToUpperInvariant ( ) ) ;
284+ section = "EnvUpperLinuxRetrace" ;
285+ }
286+
287+ if ( string . IsNullOrWhiteSpace ( v ) == false )
288+ {
289+ StackifyAPILogger . Log ( $ "#Config - #Get - Section: { section } - Key: { key } - Value: { v ?? "Empty" } ") ;
290+ }
254291 }
255292 }
256- catch ( Exception ex )
293+ catch ( Exception ex )
257294 {
258- StackifyAPILogger . Log ( "#Config #Get failed " , ex ) ;
295+ StackifyAPILogger . Log ( "#Config - #Get - #Failed " , ex ) ;
259296 }
260297 finally
261298 {
@@ -278,13 +315,11 @@ public static void ReadStackifyJSONConfig()
278315 string jsonPath = string . Empty ;
279316 string json = string . Empty ;
280317
281- ASPEnvironment = "Production" ;
282-
283- if ( ! String . IsNullOrEmpty ( ASPEnvironment ) )
318+ if ( ! String . IsNullOrWhiteSpace ( ASPEnvironment ) )
284319 {
285320 jsonPath = Path . Combine ( baseDirectory , $ "Stackify.{ ASPEnvironment } .json") ;
286321 }
287- else if ( ! String . IsNullOrEmpty ( DotnetEnvironment ) )
322+ else if ( ! String . IsNullOrWhiteSpace ( DotnetEnvironment ) )
288323 {
289324 jsonPath = Path . Combine ( baseDirectory , $ "Stackify.{ DotnetEnvironment } .json") ;
290325 }
@@ -293,6 +328,7 @@ public static void ReadStackifyJSONConfig()
293328 jsonPath = Path . Combine ( baseDirectory , "Stackify.json" ) ;
294329 }
295330
331+ StackifyAPILogger . Log ( $ "#Config #Json Load - Path: { jsonPath } ") ;
296332 if ( File . Exists ( jsonPath ) )
297333 {
298334 using ( var fs = new FileStream ( jsonPath , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) )
@@ -312,11 +348,11 @@ public static void ReadStackifyJSONConfig()
312348 string iisBaseDirectory = System . Web . Hosting . HostingEnvironment . ApplicationPhysicalPath ;
313349 string iisJsonPath = string . Empty ;
314350
315- if ( ! String . IsNullOrEmpty ( ASPEnvironment ) )
351+ if ( ! String . IsNullOrWhiteSpace ( ASPEnvironment ) )
316352 {
317353 iisJsonPath = Path . Combine ( iisBaseDirectory , $ "Stackify.{ ASPEnvironment } .json") ;
318354 }
319- else if ( ! String . IsNullOrEmpty ( DotnetEnvironment ) )
355+ else if ( ! String . IsNullOrWhiteSpace ( DotnetEnvironment ) )
320356 {
321357 iisJsonPath = Path . Combine ( iisBaseDirectory , $ "Stackify.{ DotnetEnvironment } .json") ;
322358 }
@@ -325,6 +361,7 @@ public static void ReadStackifyJSONConfig()
325361 iisJsonPath = Path . Combine ( iisBaseDirectory , "Stackify.json" ) ;
326362 }
327363
364+ StackifyAPILogger . Log ( $ "#Config #Json Load - Path: { iisJsonPath } ") ;
328365 if ( File . Exists ( iisJsonPath ) )
329366 {
330367 using ( var fs = new FileStream ( iisJsonPath , FileMode . Open , FileAccess . Read , FileShare . ReadWrite ) )
@@ -402,6 +439,7 @@ public static void SetStackifyObj(JObject obj)
402439 AppName = TryGetValue ( obj , "AppName" ) ?? AppName ;
403440 Environment = TryGetValue ( obj , "Environment" ) ?? Environment ;
404441 ApiKey = TryGetValue ( obj , "ApiKey" ) ?? ApiKey ;
442+ StackifyAPILogger . Log ( $ "#Config #Json #SetStackifyObj Load - AppName: { AppName } - Environment: { Environment } - ApiKey: { ApiKey } ") ;
405443 }
406444
407445 private static string TryGetValue ( JToken jToken , string key )
@@ -424,6 +462,7 @@ private static string TryGetValue(JToken jToken, string key)
424462 }
425463
426464 r = val . ToString ( ) ;
465+ StackifyAPILogger . Log ( $ "#Config #TryGetValue #Json Success - Key: { key } - Value: { r ?? "Empty" } ") ;
427466 }
428467 catch ( Exception ex )
429468 {
0 commit comments