33using System . Linq ;
44using System . Text ;
55using System . Diagnostics ;
6+ using StackifyLib . Utils ;
67
78namespace StackifyLib
89{
@@ -12,31 +13,28 @@ namespace StackifyLib
1213 /// </summary>
1314 public class Config
1415 {
15-
1616#if NETSTANDARD1_3 || NET451
17- private static Microsoft . Extensions . Configuration . IConfigurationRoot _Configuration = null ;
17+ private static Microsoft . Extensions . Configuration . IConfigurationRoot _configuration = null ;
1818
1919 public static void SetConfiguration ( Microsoft . Extensions . Configuration . IConfigurationRoot configuration )
2020 {
21- _Configuration = configuration ;
21+ _configuration = configuration ;
2222 }
2323#endif
24+
2425 public static void LoadSettings ( )
2526 {
2627 try
2728 {
28- CaptureErrorPostdata = Get ( "Stackify.CaptureErrorPostdata" , "" )
29- . Equals ( "true" , StringComparison . CurrentCultureIgnoreCase ) ;
29+ CaptureErrorPostdata = Get ( "Stackify.CaptureErrorPostdata" , "" ) . Equals ( bool . TrueString , StringComparison . CurrentCultureIgnoreCase ) ;
30+
31+ CaptureServerVariables = Get ( "Stackify.CaptureServerVariables" , "" ) . Equals ( bool . TrueString , StringComparison . CurrentCultureIgnoreCase ) ;
3032
31- CaptureServerVariables = Get ( "Stackify.CaptureServerVariables" , "" )
32- . Equals ( "true" , StringComparison . CurrentCultureIgnoreCase ) ;
33- CaptureSessionVariables = Get ( "Stackify.CaptureSessionVariables" , "" )
34- . Equals ( "true" , StringComparison . CurrentCultureIgnoreCase ) ;
33+ CaptureSessionVariables = Get ( "Stackify.CaptureSessionVariables" , "" ) . Equals ( bool . TrueString , StringComparison . CurrentCultureIgnoreCase ) ;
3534
36- CaptureErrorHeaders = Get ( "Stackify.CaptureErrorHeaders" , "true" ) . Equals ( "true" , StringComparison . CurrentCultureIgnoreCase ) ;
35+ CaptureErrorHeaders = Get ( "Stackify.CaptureErrorHeaders" , bool . TrueString ) . Equals ( bool . TrueString , StringComparison . CurrentCultureIgnoreCase ) ;
3736
38- CaptureErrorCookies = Get ( "Stackify.CaptureErrorCookies" , "" )
39- . Equals ( "true" , StringComparison . CurrentCultureIgnoreCase ) ;
37+ CaptureErrorCookies = Get ( "Stackify.CaptureErrorCookies" , "" ) . Equals ( bool . TrueString , StringComparison . CurrentCultureIgnoreCase ) ;
4038
4139 ApiKey = Get ( "Stackify.ApiKey" , "" ) ;
4240
@@ -46,31 +44,31 @@ public static void LoadSettings()
4644
4745 CaptureErrorHeadersWhitelist = Get ( "Stackify.CaptureErrorHeadersWhitelist" , "" ) ;
4846
49- if ( ! string . IsNullOrEmpty ( CaptureErrorHeadersWhitelist ) )
47+ if ( string . IsNullOrEmpty ( CaptureErrorHeadersWhitelist ) == false )
5048 {
5149 ErrorHeaderGoodKeys = CaptureErrorHeadersWhitelist . Split ( "," . ToCharArray ( ) , StringSplitOptions . RemoveEmptyEntries ) . ToList ( ) ;
5250 }
5351
5452 CaptureErrorHeadersBlacklist = Get ( "Stackify.CaptureErrorHeadersBlacklist" , "" ) ;
55- if ( ! string . IsNullOrEmpty ( CaptureErrorHeadersBlacklist ) )
53+ if ( string . IsNullOrEmpty ( CaptureErrorHeadersBlacklist ) == false )
5654 {
5755 ErrorHeaderBadKeys = CaptureErrorHeadersBlacklist . Split ( "," . ToCharArray ( ) , StringSplitOptions . RemoveEmptyEntries ) . ToList ( ) ;
5856 }
5957
6058 CaptureErrorCookiesWhitelist = Get ( "Stackify.CaptureErrorCookiesWhitelist" , "" ) ;
61- if ( ! string . IsNullOrEmpty ( CaptureErrorCookiesWhitelist ) )
59+ if ( string . IsNullOrEmpty ( CaptureErrorCookiesWhitelist ) == false )
6260 {
6361 ErrorCookiesGoodKeys = CaptureErrorCookiesWhitelist . Split ( "," . ToCharArray ( ) , StringSplitOptions . RemoveEmptyEntries ) . ToList ( ) ;
6462 }
6563
6664 CaptureErrorCookiesBlacklist = Get ( "Stackify.CaptureErrorCookiesBlacklist" , "" ) ;
67- if ( ! string . IsNullOrEmpty ( CaptureErrorCookiesBlacklist ) )
65+ if ( string . IsNullOrEmpty ( CaptureErrorCookiesBlacklist ) == false )
6866 {
6967 ErrorCookiesBadKeys = CaptureErrorCookiesBlacklist . Split ( "," . ToCharArray ( ) , StringSplitOptions . RemoveEmptyEntries ) . ToList ( ) ;
7068 }
7169
7270 CaptureErrorSessionWhitelist = Get ( "Stackify.CaptureErrorSessionWhitelist" , "" ) ;
73- if ( ! string . IsNullOrEmpty ( CaptureErrorSessionWhitelist ) )
71+ if ( string . IsNullOrEmpty ( CaptureErrorSessionWhitelist ) == false )
7472 {
7573 ErrorSessionGoodKeys = CaptureErrorSessionWhitelist . Split ( "," . ToCharArray ( ) , StringSplitOptions . RemoveEmptyEntries ) . ToList ( ) ;
7674 }
@@ -89,12 +87,19 @@ public static void LoadSettings()
8987 var isEc2 = Get ( "Stackify.IsEC2" , "" ) ;
9088 if ( string . IsNullOrWhiteSpace ( isEc2 ) == false )
9189 {
92- IsEc2 = isEc2 . Equals ( "true" , StringComparison . CurrentCultureIgnoreCase ) ;
90+ IsEc2 = isEc2 . Equals ( bool . TrueString , StringComparison . CurrentCultureIgnoreCase ) ;
9391 }
94- }
92+
93+ // RT-297
94+ var apiLog = Get ( "Stackify.ApiLog" , "" ) ;
95+ if ( string . IsNullOrWhiteSpace ( apiLog ) == false )
96+ {
97+ ApiLog = apiLog . Equals ( bool . TrueString , StringComparison . CurrentCultureIgnoreCase ) ;
98+ }
99+ }
95100 catch ( Exception ex )
96101 {
97- Debug . WriteLine ( ex . ToString ( ) ) ;
102+ StackifyAPILogger . Log ( "#Config #LoadSettings failed" , ex ) ;
98103 }
99104 }
100105
@@ -129,6 +134,7 @@ public static void LoadSettings()
129134
130135 public static bool ? IsEc2 { get ; set ; } = null ;
131136
137+ public static bool ? ApiLog { get ; set ; } = null ;
132138
133139 /// <summary>
134140 /// Attempts to fetch a setting value given the key.
@@ -140,35 +146,41 @@ public static void LoadSettings()
140146 internal static string Get ( string key , string defaultValue = null )
141147 {
142148 string v = null ;
149+
143150 try
144151 {
145152 if ( key != null )
146153 {
147-
148-
149154#if NETSTANDARD1_3 || NET451
150- if ( _Configuration != null )
155+ if ( _configuration != null )
151156 {
152- var appSettings = _Configuration . GetSection ( "Stackify" ) ;
157+ var appSettings = _configuration . GetSection ( "Stackify" ) ;
153158 v = appSettings [ key . Replace ( "Stackify." , "" ) ] ;
154159 }
155160#endif
156161
157- #if NET451 || NET45 || NET40
158- if ( string . IsNullOrEmpty ( v ) )
159- v = System . Configuration . ConfigurationManager . AppSettings [ key ] ;
162+ #if NET451 || NET45
163+ if ( string . IsNullOrEmpty ( v ) )
164+ {
165+ v = System . Configuration . ConfigurationManager . AppSettings [ key ] ;
166+ }
160167#endif
161168
162- if ( string . IsNullOrEmpty ( v ) )
163- v = System . Environment . GetEnvironmentVariable ( key ) ;
169+ if ( string . IsNullOrEmpty ( v ) )
170+ {
171+ v = System . Environment . GetEnvironmentVariable ( key ) ;
172+ }
164173 }
165174 }
166175 finally
167176 {
168- if ( v == null )
169- v = defaultValue ;
177+ if ( v == null )
178+ {
179+ v = defaultValue ;
180+ }
170181 }
182+
171183 return v ;
172184 }
173185 }
174- }
186+ }
0 commit comments