3
3
using System . Linq ;
4
4
using System . Text ;
5
5
using System . Diagnostics ;
6
+ using StackifyLib . Utils ;
6
7
7
8
namespace StackifyLib
8
9
{
@@ -12,31 +13,28 @@ namespace StackifyLib
12
13
/// </summary>
13
14
public class Config
14
15
{
15
-
16
16
#if NETSTANDARD1_3 || NET451
17
- private static Microsoft . Extensions . Configuration . IConfigurationRoot _Configuration = null ;
17
+ private static Microsoft . Extensions . Configuration . IConfigurationRoot _configuration = null ;
18
18
19
19
public static void SetConfiguration ( Microsoft . Extensions . Configuration . IConfigurationRoot configuration )
20
20
{
21
- _Configuration = configuration ;
21
+ _configuration = configuration ;
22
22
}
23
23
#endif
24
+
24
25
public static void LoadSettings ( )
25
26
{
26
27
try
27
28
{
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 ) ;
30
32
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 ) ;
35
34
36
- CaptureErrorHeaders = Get ( "Stackify.CaptureErrorHeaders" , "true" ) . Equals ( "true" , StringComparison . CurrentCultureIgnoreCase ) ;
35
+ CaptureErrorHeaders = Get ( "Stackify.CaptureErrorHeaders" , bool . TrueString ) . Equals ( bool . TrueString , StringComparison . CurrentCultureIgnoreCase ) ;
37
36
38
- CaptureErrorCookies = Get ( "Stackify.CaptureErrorCookies" , "" )
39
- . Equals ( "true" , StringComparison . CurrentCultureIgnoreCase ) ;
37
+ CaptureErrorCookies = Get ( "Stackify.CaptureErrorCookies" , "" ) . Equals ( bool . TrueString , StringComparison . CurrentCultureIgnoreCase ) ;
40
38
41
39
ApiKey = Get ( "Stackify.ApiKey" , "" ) ;
42
40
@@ -46,31 +44,31 @@ public static void LoadSettings()
46
44
47
45
CaptureErrorHeadersWhitelist = Get ( "Stackify.CaptureErrorHeadersWhitelist" , "" ) ;
48
46
49
- if ( ! string . IsNullOrEmpty ( CaptureErrorHeadersWhitelist ) )
47
+ if ( string . IsNullOrEmpty ( CaptureErrorHeadersWhitelist ) == false )
50
48
{
51
49
ErrorHeaderGoodKeys = CaptureErrorHeadersWhitelist . Split ( "," . ToCharArray ( ) , StringSplitOptions . RemoveEmptyEntries ) . ToList ( ) ;
52
50
}
53
51
54
52
CaptureErrorHeadersBlacklist = Get ( "Stackify.CaptureErrorHeadersBlacklist" , "" ) ;
55
- if ( ! string . IsNullOrEmpty ( CaptureErrorHeadersBlacklist ) )
53
+ if ( string . IsNullOrEmpty ( CaptureErrorHeadersBlacklist ) == false )
56
54
{
57
55
ErrorHeaderBadKeys = CaptureErrorHeadersBlacklist . Split ( "," . ToCharArray ( ) , StringSplitOptions . RemoveEmptyEntries ) . ToList ( ) ;
58
56
}
59
57
60
58
CaptureErrorCookiesWhitelist = Get ( "Stackify.CaptureErrorCookiesWhitelist" , "" ) ;
61
- if ( ! string . IsNullOrEmpty ( CaptureErrorCookiesWhitelist ) )
59
+ if ( string . IsNullOrEmpty ( CaptureErrorCookiesWhitelist ) == false )
62
60
{
63
61
ErrorCookiesGoodKeys = CaptureErrorCookiesWhitelist . Split ( "," . ToCharArray ( ) , StringSplitOptions . RemoveEmptyEntries ) . ToList ( ) ;
64
62
}
65
63
66
64
CaptureErrorCookiesBlacklist = Get ( "Stackify.CaptureErrorCookiesBlacklist" , "" ) ;
67
- if ( ! string . IsNullOrEmpty ( CaptureErrorCookiesBlacklist ) )
65
+ if ( string . IsNullOrEmpty ( CaptureErrorCookiesBlacklist ) == false )
68
66
{
69
67
ErrorCookiesBadKeys = CaptureErrorCookiesBlacklist . Split ( "," . ToCharArray ( ) , StringSplitOptions . RemoveEmptyEntries ) . ToList ( ) ;
70
68
}
71
69
72
70
CaptureErrorSessionWhitelist = Get ( "Stackify.CaptureErrorSessionWhitelist" , "" ) ;
73
- if ( ! string . IsNullOrEmpty ( CaptureErrorSessionWhitelist ) )
71
+ if ( string . IsNullOrEmpty ( CaptureErrorSessionWhitelist ) == false )
74
72
{
75
73
ErrorSessionGoodKeys = CaptureErrorSessionWhitelist . Split ( "," . ToCharArray ( ) , StringSplitOptions . RemoveEmptyEntries ) . ToList ( ) ;
76
74
}
@@ -89,12 +87,19 @@ public static void LoadSettings()
89
87
var isEc2 = Get ( "Stackify.IsEC2" , "" ) ;
90
88
if ( string . IsNullOrWhiteSpace ( isEc2 ) == false )
91
89
{
92
- IsEc2 = isEc2 . Equals ( "true" , StringComparison . CurrentCultureIgnoreCase ) ;
90
+ IsEc2 = isEc2 . Equals ( bool . TrueString , StringComparison . CurrentCultureIgnoreCase ) ;
93
91
}
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
+ }
95
100
catch ( Exception ex )
96
101
{
97
- Debug . WriteLine ( ex . ToString ( ) ) ;
102
+ StackifyAPILogger . Log ( "#Config #LoadSettings failed" , ex ) ;
98
103
}
99
104
}
100
105
@@ -129,6 +134,7 @@ public static void LoadSettings()
129
134
130
135
public static bool ? IsEc2 { get ; set ; } = null ;
131
136
137
+ public static bool ? ApiLog { get ; set ; } = null ;
132
138
133
139
/// <summary>
134
140
/// Attempts to fetch a setting value given the key.
@@ -140,35 +146,41 @@ public static void LoadSettings()
140
146
internal static string Get ( string key , string defaultValue = null )
141
147
{
142
148
string v = null ;
149
+
143
150
try
144
151
{
145
152
if ( key != null )
146
153
{
147
-
148
-
149
154
#if NETSTANDARD1_3 || NET451
150
- if ( _Configuration != null )
155
+ if ( _configuration != null )
151
156
{
152
- var appSettings = _Configuration . GetSection ( "Stackify" ) ;
157
+ var appSettings = _configuration . GetSection ( "Stackify" ) ;
153
158
v = appSettings [ key . Replace ( "Stackify." , "" ) ] ;
154
159
}
155
160
#endif
156
161
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
+ }
160
167
#endif
161
168
162
- if ( string . IsNullOrEmpty ( v ) )
163
- v = System . Environment . GetEnvironmentVariable ( key ) ;
169
+ if ( string . IsNullOrEmpty ( v ) )
170
+ {
171
+ v = System . Environment . GetEnvironmentVariable ( key ) ;
172
+ }
164
173
}
165
174
}
166
175
finally
167
176
{
168
- if ( v == null )
169
- v = defaultValue ;
177
+ if ( v == null )
178
+ {
179
+ v = defaultValue ;
180
+ }
170
181
}
182
+
171
183
return v ;
172
184
}
173
185
}
174
- }
186
+ }
0 commit comments