From 6bcc8a248fba044a19dd0f9826a7596832394fc5 Mon Sep 17 00:00:00 2001 From: Dan Gidman Date: Tue, 7 Feb 2017 13:48:30 -0600 Subject: [PATCH 1/3] SF-6393 Adding Order to Milliseconds --- Src/StackifyLib/Internal/Logs/LogClient.cs | 25 ++++++++++++++++++++++ Src/StackifyLib/Models/LogMsgGroup.cs | 3 +++ 2 files changed, 28 insertions(+) diff --git a/Src/StackifyLib/Internal/Logs/LogClient.cs b/Src/StackifyLib/Internal/Logs/LogClient.cs index 8701bbd..0bc508f 100644 --- a/Src/StackifyLib/Internal/Logs/LogClient.cs +++ b/Src/StackifyLib/Internal/Logs/LogClient.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Net; using System.Text; +using System.Threading; using System.Threading.Tasks; //using System.Web.Configuration; using Newtonsoft.Json; @@ -123,6 +124,13 @@ public bool ErrorShouldBeSent(StackifyError error) return governor.ErrorShouldBeSent(error); } + + + private long? LastEpochMs = 0; + private object locker = new object(); + private int count; + + public void QueueMessage(LogMsg msg) { if (msg == null) return; @@ -139,6 +147,23 @@ public void QueueMessage(LogMsg msg) isError = 1; } + // works on the assumption that the epochMS will always be incrementing as it reaches this point + if (LastEpochMs < msg.EpochMs) + { + // reset counter if we are no longer in the same ms + lock (locker) + { + //https://msdn.microsoft.com/en-us/library/system.threading.interlocked_methods(v=vs.110).aspx + LastEpochMs = msg.EpochMs; + Interlocked.Exchange(ref count, 0); + msg.Order = 0; + } + } + else + { + msg.Order = Interlocked.Increment(ref count); + } + //Used by Stackify profiler only if (Logger.PrefixEnabled()) { diff --git a/Src/StackifyLib/Models/LogMsgGroup.cs b/Src/StackifyLib/Models/LogMsgGroup.cs index 8533a9e..347f086 100644 --- a/Src/StackifyLib/Models/LogMsgGroup.cs +++ b/Src/StackifyLib/Models/LogMsgGroup.cs @@ -95,6 +95,9 @@ public LogMsg() [JsonProperty] public List Tags { get; set; } + [JsonProperty(PropertyName = "order")] + public int Order { get; set; } + [JsonIgnore] public LogMsgGroup AppDetails { get; set; } From 07ce8d305219217742cd16da08de34842f749b26 Mon Sep 17 00:00:00 2001 From: Dan Gidman Date: Tue, 7 Feb 2017 14:11:46 -0600 Subject: [PATCH 2/3] SF-6393 Adding Order to Milliseconds - refactor --- Src/StackifyLib/Internal/Logs/LogClient.cs | 24 +++++++++------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Src/StackifyLib/Internal/Logs/LogClient.cs b/Src/StackifyLib/Internal/Logs/LogClient.cs index 0bc508f..1ce40c6 100644 --- a/Src/StackifyLib/Internal/Logs/LogClient.cs +++ b/Src/StackifyLib/Internal/Logs/LogClient.cs @@ -126,10 +126,8 @@ public bool ErrorShouldBeSent(StackifyError error) - private long? LastEpochMs = 0; - private object locker = new object(); - private int count; - + private static long _lastEpochMs = 0; + private static int _millisecondCount = 0; public void QueueMessage(LogMsg msg) { @@ -148,21 +146,19 @@ public void QueueMessage(LogMsg msg) } // works on the assumption that the epochMS will always be incrementing as it reaches this point - if (LastEpochMs < msg.EpochMs) + if (_lastEpochMs < msg.EpochMs) { // reset counter if we are no longer in the same ms - lock (locker) - { - //https://msdn.microsoft.com/en-us/library/system.threading.interlocked_methods(v=vs.110).aspx - LastEpochMs = msg.EpochMs; - Interlocked.Exchange(ref count, 0); - msg.Order = 0; - } + //https://msdn.microsoft.com/en-us/library/system.threading.interlocked_methods(v=vs.110).aspx + Interlocked.Exchange(ref _lastEpochMs, msg.EpochMs); + Interlocked.Exchange(ref _millisecondCount, 0); + msg.Order = 0; } - else + else if (_lastEpochMs == msg.EpochMs) { - msg.Order = Interlocked.Increment(ref count); + msg.Order = Interlocked.Increment(ref _millisecondCount); } + // else defaulted to 0 //Used by Stackify profiler only if (Logger.PrefixEnabled()) From ac92920a315c1d0b5285f6b4d09853f192c4b7a2 Mon Sep 17 00:00:00 2001 From: Daniel Gidman Date: Tue, 7 Feb 2017 14:13:53 -0600 Subject: [PATCH 3/3] Removing Name Override --- Src/StackifyLib/Models/LogMsgGroup.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/StackifyLib/Models/LogMsgGroup.cs b/Src/StackifyLib/Models/LogMsgGroup.cs index 347f086..03897f3 100644 --- a/Src/StackifyLib/Models/LogMsgGroup.cs +++ b/Src/StackifyLib/Models/LogMsgGroup.cs @@ -95,7 +95,7 @@ public LogMsg() [JsonProperty] public List Tags { get; set; } - [JsonProperty(PropertyName = "order")] + [JsonProperty] public int Order { get; set; } [JsonIgnore]