Skip to content

Commit 4bd588e

Browse files
author
mwatson
committed
Minor try catch error changes to prevent potential issues
1 parent 489b524 commit 4bd588e

File tree

4 files changed

+22
-29
lines changed

4 files changed

+22
-29
lines changed

Src/StackifyLib/Internal/Metrics/MetricClient.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -323,29 +323,31 @@ private static void UploadMetricsCheck(object state)
323323

324324
public static void StopMetricsQueue(string reason = "Unknown")
325325
{
326-
StackifyAPILogger.Log("StopMetricsQueue called by " + reason, true);
327-
328-
//don't let t his method run more than once
329-
if (_StopRequested)
330-
return;
331326

332-
_StopRequested = true;
333327

334328
try
335329
{
330+
StackifyAPILogger.Log("StopMetricsQueue called by " + reason, true);
331+
332+
//don't let t his method run more than once
333+
if (_StopRequested)
334+
return;
335+
336+
_StopRequested = true;
337+
336338
DateTime currentMinute = DateTime.UtcNow.AddMinutes(2).Floor(TimeSpan.FromMinutes(1));
337339

338340
UploadMetrics(currentMinute);
339341

342+
_StopRequested = false;
343+
StackifyAPILogger.Log("StopMetricsQueue completed" + reason, true);
340344
}
341345
catch (Exception ex)
342346
{
343347
StackifyAPILogger.Log("StopMetricsQueue error" + ex.ToString(), true);
344348
}
345349

346350

347-
_StopRequested = false;
348-
StackifyAPILogger.Log("StopMetricsQueue completed" + reason, true);
349351
}
350352

351353
public static bool UploadMetrics(DateTime currentMinute)

Src/StackifyLib/Utils/HttpClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public HttpClient(string apiKey, string apiUrl)
108108
}
109109
_LastIdentityAttempt = DateTime.UtcNow.AddMinutes(-15);
110110

111-
if (!BaseAPIUrl.EndsWith("/"))
111+
if (BaseAPIUrl != null && !BaseAPIUrl.EndsWith("/"))
112112
BaseAPIUrl += "/";
113113
}
114114

Src/StackifyLib/Utils/StackifyAPILogger.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,25 @@ public static StringWriter Logger
4848

4949
public static void Log(string message, bool logAnyways = false)
5050
{
51-
if (logAnyways || (_LogEnabled ?? false))
51+
try
5252
{
53-
if (OnLogMessage != null)
53+
if (logAnyways || (_LogEnabled ?? false))
5454
{
55-
try
55+
OnLogMessage?.Invoke("StackifyLib: " + message);
56+
57+
if (_Logger != null)
5658
{
57-
OnLogMessage("StackifyLib: " + message);
59+
_Logger.Write("StackifyLib: " + message);
5860
}
59-
catch (Exception)
61+
else
6062
{
61-
63+
Debug.WriteLine("StackifyLib: " + message);
6264
}
6365
}
66+
}
67+
catch
68+
{
6469

65-
if (_Logger != null)
66-
{
67-
_Logger.Write("StackifyLib: " + message);
68-
}
69-
else
70-
{
71-
Debug.WriteLine("StackifyLib: " + message);
72-
}
7370
}
7471

7572
}

Src/StackifyLibCore.sln

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "NLog.Targets.Stackify", "NL
1313
EndProject
1414
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StackifyLib.ELMAH", "StackifyLib.ELMAH\StackifyLib.ELMAH.csproj", "{D0E1AABD-6397-4CC7-9737-4904A4BF5BCD}"
1515
EndProject
16-
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.Stackify", "Serilog.Sinks.Stackify\Serilog.Sinks.Stackify.xproj", "{5A144848-A7C9-4D61-A4F0-E3DAF7FBF994}"
17-
EndProject
1816
Global
1917
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2018
Debug|Any CPU = Debug|Any CPU
@@ -41,10 +39,6 @@ Global
4139
{D0E1AABD-6397-4CC7-9737-4904A4BF5BCD}.Debug|Any CPU.Build.0 = Debug|Any CPU
4240
{D0E1AABD-6397-4CC7-9737-4904A4BF5BCD}.Release|Any CPU.ActiveCfg = Release|Any CPU
4341
{D0E1AABD-6397-4CC7-9737-4904A4BF5BCD}.Release|Any CPU.Build.0 = Release|Any CPU
44-
{5A144848-A7C9-4D61-A4F0-E3DAF7FBF994}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45-
{5A144848-A7C9-4D61-A4F0-E3DAF7FBF994}.Debug|Any CPU.Build.0 = Debug|Any CPU
46-
{5A144848-A7C9-4D61-A4F0-E3DAF7FBF994}.Release|Any CPU.ActiveCfg = Release|Any CPU
47-
{5A144848-A7C9-4D61-A4F0-E3DAF7FBF994}.Release|Any CPU.Build.0 = Release|Any CPU
4842
EndGlobalSection
4943
GlobalSection(SolutionProperties) = preSolution
5044
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)