Skip to content

Commit 26b53a6

Browse files
author
mwatson
committed
2 parents 115a234 + 42b08d9 commit 26b53a6

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ Library for Stackify users to integrate Stackify in to their projects. Provides
44

55
**Important links:**
66
- [Stackify homepage](http://www.stackify.com)
7-
- [Stackify documentation site](http://docs.stackify.com/s/3095/m/7787)
7+
- [Stackify documentation site](http://support.stackify.com/hc/en-us/categories/200398739-Errors-Logs)
88
- [NuGet packages](https://www.nuget.org/packages?q=Stackify)
9+
- [Best practices for logging with C#](https://stackify.com/csharp-logging-best-practices/)
10+
- [Why you should use tags in your logs](https://stackify.com/get-smarter-log-management-with-log-tags/)
11+
912

1013
**Read me sections:**
1114
- [Basics](#basics)

Src/StackifyLib/Internal/Logs/LogClient.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Net;
66
using System.Text;
7+
using System.Threading;
78
using System.Threading.Tasks;
89
//using System.Web.Configuration;
910
using Newtonsoft.Json;
@@ -123,6 +124,11 @@ public bool ErrorShouldBeSent(StackifyError error)
123124
return governor.ErrorShouldBeSent(error);
124125
}
125126

127+
128+
129+
private static long _lastEpochMs = 0;
130+
private static int _millisecondCount = 0;
131+
126132
public void QueueMessage(LogMsg msg)
127133
{
128134
if (msg == null) return;
@@ -139,6 +145,21 @@ public void QueueMessage(LogMsg msg)
139145
isError = 1;
140146
}
141147

148+
// works on the assumption that the epochMS will always be incrementing as it reaches this point
149+
if (_lastEpochMs < msg.EpochMs)
150+
{
151+
// reset counter if we are no longer in the same ms
152+
//https://msdn.microsoft.com/en-us/library/system.threading.interlocked_methods(v=vs.110).aspx
153+
Interlocked.Exchange(ref _lastEpochMs, msg.EpochMs);
154+
Interlocked.Exchange(ref _millisecondCount, 0);
155+
msg.Order = 0;
156+
}
157+
else if (_lastEpochMs == msg.EpochMs)
158+
{
159+
msg.Order = Interlocked.Increment(ref _millisecondCount);
160+
}
161+
// else defaulted to 0
162+
142163
//Used by Stackify profiler only
143164
if (Logger.PrefixEnabled())
144165
{

Src/StackifyLib/Models/LogMsgGroup.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ public LogMsg()
9999
[JsonProperty]
100100
public List<string> Tags { get; set; }
101101

102+
[JsonProperty]
103+
public int Order { get; set; }
104+
102105
[JsonIgnore]
103106
public LogMsgGroup AppDetails { get; set; }
104107

0 commit comments

Comments
 (0)