From 3176a6ee28f5659164ccdedb0e4204ca89c92c9f Mon Sep 17 00:00:00 2001 From: Paul Marvin Date: Fri, 22 Dec 2017 10:35:56 -0600 Subject: [PATCH] RT-89: GetSystemTimePreciseAsFileTime not supported pre Windows 8 --- Src/StackifyLib/Constants.cs | 11 ++++++ Src/StackifyLib/Internal/Logs/LogQueue.cs | 6 +-- Src/StackifyLib/Models/LogMsgGroup.cs | 46 +++++++++++----------- Src/StackifyLib/Utils/HighPrecisionTime.cs | 45 --------------------- 4 files changed, 37 insertions(+), 71 deletions(-) create mode 100644 Src/StackifyLib/Constants.cs delete mode 100644 Src/StackifyLib/Utils/HighPrecisionTime.cs diff --git a/Src/StackifyLib/Constants.cs b/Src/StackifyLib/Constants.cs new file mode 100644 index 0000000..e769fac --- /dev/null +++ b/Src/StackifyLib/Constants.cs @@ -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); + } +} diff --git a/Src/StackifyLib/Internal/Logs/LogQueue.cs b/Src/StackifyLib/Internal/Logs/LogQueue.cs index b856f22..d5bf9d6 100644 --- a/Src/StackifyLib/Internal/Logs/LogQueue.cs +++ b/Src/StackifyLib/Internal/Logs/LogQueue.cs @@ -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 _MessageBuffer = null; private System.Threading.Timer _timer = null; private TimeSpan _FlushInterval = TimeSpan.FromSeconds(1); @@ -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) { @@ -331,7 +329,7 @@ private int FlushOnce() var chunk = new List(); //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 { diff --git a/Src/StackifyLib/Models/LogMsgGroup.cs b/Src/StackifyLib/Models/LogMsgGroup.cs index ff31fe6..8553aa3 100644 --- a/Src/StackifyLib/Models/LogMsgGroup.cs +++ b/Src/StackifyLib/Models/LogMsgGroup.cs @@ -1,11 +1,7 @@ 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 { @@ -13,22 +9,31 @@ 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; } @@ -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; } @@ -64,29 +62,34 @@ 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; } @@ -94,7 +97,7 @@ public LogMsg() public int? SrcLine { get; set; } [JsonProperty] - public string id { get; set; } //unique id + public string id { get; set; } // unique id [JsonProperty] public List Tags { get; set; } @@ -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; } } -} +} \ No newline at end of file diff --git a/Src/StackifyLib/Utils/HighPrecisionTime.cs b/Src/StackifyLib/Utils/HighPrecisionTime.cs deleted file mode 100644 index 985fe0e..0000000 --- a/Src/StackifyLib/Utils/HighPrecisionTime.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Threading.Tasks; - -namespace StackifyLib.Utils -{ - public static class HighPrecisionTime - { - public static bool IsAvailable { get; private set; } - - [DllImport("Kernel32.dll", CallingConvention = CallingConvention.Winapi)] - private static extern void GetSystemTimePreciseAsFileTime(out long filetime); - - public static DateTime UtcNow - { - get - { - if (!IsAvailable) - { - return DateTime.UtcNow; - // throw new InvalidOperationException("High resolution clock isn't available."); - } - long filetime; - GetSystemTimePreciseAsFileTime(out filetime); - return DateTime.FromFileTimeUtc(filetime); - } - } - - static HighPrecisionTime() - { - try - { - long filetime; - GetSystemTimePreciseAsFileTime(out filetime); - IsAvailable = true; - } - catch - { - IsAvailable = false; - } - } - } -}