-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathAsyncTracer.cs
More file actions
76 lines (63 loc) · 2.25 KB
/
Copy pathAsyncTracer.cs
File metadata and controls
76 lines (63 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#if NETFULL
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
namespace StackifyLib.Utils
{
public class AsyncTracer
{
private static bool _AsyncTracerEnabled = false;
private static DateTime _LastEnabledTest = DateTime.MinValue;
public static bool EnsureAsyncTracer()
{
if (_AsyncTracerEnabled)
return _AsyncTracerEnabled;
if (_LastEnabledTest > DateTime.UtcNow.AddMinutes(-5))
{
return _AsyncTracerEnabled;
}
try
{
var t = Type.GetType("System.Threading.Tasks.AsyncCausalityTracer");
if (t != null)
{
var field = t.GetField("f_LoggingOn", BindingFlags.NonPublic | BindingFlags.Static);
if (field == null)
{
StackifyLib.Utils.StackifyAPILogger.Log("Unable to enable the AsyncCausalityTracer, f_LoggingOn field not found");
return _AsyncTracerEnabled;
}
if (field.FieldType.Name == "Boolean")
{
bool current = (bool)field.GetValue(null);
if (!current)
{
field.SetValue(null, true);
}
}
else
{
field.SetValue(null, (byte)4);
}
_AsyncTracerEnabled = true;
}
else
{
_AsyncTracerEnabled = true; //never going to work.
StackifyLib.Utils.StackifyAPILogger.Log("Unable to enable the AsyncCausalityTracer, class not found");
}
}
catch (Exception ex)
{
StackifyLib.Utils.StackifyAPILogger.Log("EnsureAsyncTracer Exception: " + ex.ToString());
Debug.WriteLine(ex);
}
_LastEnabledTest = DateTime.UtcNow;
return _AsyncTracerEnabled;
}
}
}
#endif