Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Src/StackifyLib/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace StackifyLib
{
public static class Constants
{
public static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
}
}
6 changes: 2 additions & 4 deletions Src/StackifyLib/Internal/Logs/LogQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ namespace StackifyLib.Internal.Logs
{
internal class LogQueue
{
static DateTime _Epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0);

private ConcurrentQueue<Models.LogMsg> _MessageBuffer = null;
private System.Threading.Timer _timer = null;
private TimeSpan _FlushInterval = TimeSpan.FromSeconds(1);
Expand Down Expand Up @@ -201,7 +199,7 @@ private void OnTimer(Object stateInfo)
//remove messages in the queue that are old
if (!_LogClient.IsAuthorized() && _MessageBuffer.Count > 0)
{
var cutoff = (long)DateTime.UtcNow.AddMinutes(-5).Subtract(_Epoch).TotalMilliseconds;
var cutoff = (long)DateTime.UtcNow.AddMinutes(-5).Subtract(Constants.Epoch).TotalMilliseconds;

while (true)
{
Expand Down Expand Up @@ -331,7 +329,7 @@ private int FlushOnce()
var chunk = new List<LogMsg>();

//we only want to do this once at a time but the actual send is done async
long startMs = (long)DateTime.UtcNow.Subtract(_Epoch).TotalMilliseconds;
long startMs = (long)DateTime.UtcNow.Subtract(Constants.Epoch).TotalMilliseconds;

try
{
Expand Down
46 changes: 24 additions & 22 deletions Src/StackifyLib/Models/LogMsgGroup.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Text;
using Newtonsoft.Json;
using StackifyLib.Utils;

namespace StackifyLib.Models
{
public class LogMsgGroup
{
[JsonProperty]
public int? CDID { get; set; }

[JsonProperty]
public int? CDAppID { get; set; }

[JsonProperty]
public Guid? AppNameID { get; set; }

[JsonProperty]
public Guid? AppEnvID { get; set; }

[JsonProperty]
public short? EnvID { get; set; }

[JsonProperty]
public string Env { get; set; }

[JsonProperty]
public string ServerName { get; set; }

[JsonProperty]
public string AppName { get; set; }

[JsonProperty]
public string AppLoc { get; set; }

[JsonProperty]
public string Logger { get; set; }

Expand All @@ -40,22 +45,15 @@ public class LogMsgGroup

public string GetUniqueKey()
{
return (Logger ?? "") + "" + ServerName + "-" + AppName + "-" + Env + "-" + (EnvID ?? 0) + "-" + (CDID ?? 0) + "-" +
(CDAppID ?? 0);
return (Logger ?? string.Empty) + "" + ServerName + "-" + AppName + "-" + Env + "-" + (EnvID ?? 0) + "-" + (CDID ?? 0) + "-" + (CDAppID ?? 0);
}

}

public class LogMsg
{
private static DateTime _Epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0);

public LogMsg()
{
EpochMs = (long)HighPrecisionTime.UtcNow.Subtract(_Epoch).TotalMilliseconds;

//Switched to high precision timer
//EpochMs = (long)DateTime.UtcNow.Subtract(_Epoch).TotalMilliseconds;
EpochMs = (long)DateTime.UtcNow.Subtract(Constants.Epoch).TotalMilliseconds;
UploadErrors = 0;
}

Expand All @@ -64,37 +62,42 @@ public LogMsg()

[JsonProperty]
public string Msg { get; set; }

[JsonProperty]
public string data { get; set; } //serialized object as json
public string data { get; set; } // serialized object as json

[JsonProperty]
public StackifyError Ex { get; set; }

[JsonProperty]
public string Th { get; set; } //thread
public string Th { get; set; } // thread

[JsonProperty]
public string ThOs { get; set; } //OS thread number
public string ThOs { get; set; } // OS thread number

[JsonProperty]
public string TransID { get; set; } //transaction ID
public string TransID { get; set; } // transaction ID

[JsonProperty]
public long EpochMs { get; set; }

[JsonProperty]
public string Level { get; set; }

[JsonProperty]
public string UrlRoute { get; set; }


[JsonProperty]
public string UrlFull { get; set; }


[JsonProperty]
public string SrcMethod { get; set; }

[JsonProperty]
public int? SrcLine { get; set; }

[JsonProperty]
public string id { get; set; } //unique id
public string id { get; set; } // unique id

[JsonProperty]
public List<string> Tags { get; set; }
Expand All @@ -105,11 +108,10 @@ public LogMsg()
[JsonIgnore]
public LogMsgGroup AppDetails { get; set; }


[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.PreserveSig | MethodImplOptions.NoOptimization)]
public void SetLogMsgID(string id, int isError, string logLevel, string logMsg, string logData)
{
this.id = id;
}
}
}
}
45 changes: 0 additions & 45 deletions Src/StackifyLib/Utils/HighPrecisionTime.cs

This file was deleted.