Skip to content

Commit 752a2ba

Browse files
committed
RT-297: StackifyLib
* Internal logging improvements * Consistency check compile constants
1 parent 4a3cb22 commit 752a2ba

File tree

13 files changed

+309
-237
lines changed

13 files changed

+309
-237
lines changed

.gitignore

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
1-
################################################################################
2-
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
3-
################################################################################
1+
#Ignore thumbnails created by Windows
2+
Thumbs.db
43

5-
/CoreSrc/StackifyLib/bin/Debug/netcoreapp1.0/StackifyLib.pdb
6-
Src/StackifyLib.log4net/project.lock.json
4+
#Ignore files built by Visual Studio
5+
*.obj
6+
*.exe
7+
*.pdb
8+
*.user
9+
*.aps
10+
*.pch
11+
*.vspscc
12+
*_i.c
13+
*_p.c
14+
*.ncb
15+
*.suo
16+
*.tlb
17+
*.tlh
18+
*.bak
19+
*.cache
20+
*.ilk
21+
*.log
22+
*.dll
23+
*.lib
24+
*.sbr
25+
.idea/
26+
_ReSharper.Caches/
27+
packages/
28+
*.lock.json
29+
30+
**/bin/*
31+
**/obj/*

Src/NLog.Targets.Stackify/StackifyTarget.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ private Dictionary<string, object> GetDiagnosticContextProperties()
151151
}
152152
}
153153
}
154-
#if NET45 || NET40
154+
155+
#if NET45 || NET40
155156

156157
foreach (string key in _CallContextKeys)
157158
{
@@ -163,8 +164,8 @@ private Dictionary<string, object> GetDiagnosticContextProperties()
163164
}
164165
}
165166
#endif
166-
return properties;
167167

168+
return properties;
168169
}
169170

170171
internal LogMsg Translate(LogEventInfo loggingEvent)

Src/StackifyLib/Config.cs

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Text;
55
using System.Diagnostics;
6+
using StackifyLib.Utils;
67

78
namespace 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+
}

Src/StackifyLib/Extensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Linq;
77
using System.Text;
88
using System.Threading.Tasks;
9+
using StackifyLib.Utils;
910

1011
namespace StackifyLib
1112
{
@@ -19,7 +20,7 @@ public static void SendToStackify(this Exception ex)
1920
}
2021
catch (Exception e)
2122
{
22-
Debug.WriteLine("Error submitting error to Stackify " + e.ToString());
23+
StackifyAPILogger.Log("#Extensions #SendToStackify failed", e);
2324
throw;
2425
}
2526
}
@@ -32,7 +33,7 @@ public static StackifyLib.StackifyError NewStackifyError(this Exception ex)
3233
}
3334
catch (Exception e)
3435
{
35-
Debug.WriteLine("Error submitting error to Stackify " + e.ToString());
36+
StackifyAPILogger.Log("#Extensions #NewStackifyError failed", e);
3637
throw;
3738
}
3839
}

0 commit comments

Comments
 (0)