Skip to content

Commit

Permalink
Fix #142
Browse files Browse the repository at this point in the history
  • Loading branch information
karolz-ms committed Oct 20, 2017
1 parent c1f8ab2 commit 60b65ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Linq;
using System.Diagnostics.Tracing;
using System.Diagnostics;
using System.Threading;
#if !NETSTANDARD1_6
using System.Runtime.InteropServices;
#endif
Expand All @@ -22,6 +23,8 @@ internal static class EventDataExtensions
#if !NETSTANDARD1_6
[DllImport("Kernel32.dll", CallingConvention = CallingConvention.Winapi)]
private static extern void GetSystemTimePreciseAsFileTime(out long filetime);

private static bool hasPreciseTime = Environment.OSVersion.Version.Major >= 10 || (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor >= 2);
#endif

public static EventData ToEventData(this EventWrittenEventArgs eventSourceEvent, IHealthReporter healthReporter, string context)
Expand All @@ -35,8 +38,16 @@ public static EventData ToEventData(this EventWrittenEventArgs eventSourceEvent,
#if NETSTANDARD1_6
DateTime now = DateTime.UtcNow;
#else
GetSystemTimePreciseAsFileTime(out long filetime);
DateTime now = DateTime.FromFileTimeUtc(filetime);
DateTime now;
if (hasPreciseTime)
{
GetSystemTimePreciseAsFileTime(out long filetime);
now = DateTime.FromFileTimeUtc(filetime);
}
else
{
now = DateTime.UtcNow;
}
#endif
EventData eventData = new EventData
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Description>Provides an input implementation for capturing diagnostics data sourced through System.Diagnostics.Tracing.EventSource infrastructure.</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<VersionPrefix>1.1.3</VersionPrefix>
<VersionPrefix>1.1.4</VersionPrefix>
<Authors>Microsoft</Authors>
<TargetFrameworks>netstandard1.6;net46</TargetFrameworks>
<DelaySign>true</DelaySign>
Expand Down

0 comments on commit 60b65ec

Please sign in to comment.