-
Notifications
You must be signed in to change notification settings - Fork 3
/
Tracer.cs
59 lines (56 loc) · 1.63 KB
/
Tracer.cs
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
// version history
// februar 18, 2016 | soren granfeldt
// - added TraceError for text only parameter
// - removed
// september 12, 2018 | soren granfeldt
// - removed Indent and Unident (for speed)
using System;
using System.Diagnostics;
namespace Granfeldt
{
public static class Tracer
{
//TODO: convert ident to stringbuilder
const string SwitchName = "MRE";
const string SourceName = "FIM.MRE";
public static TraceSource Trace = new TraceSource(SourceName, SourceLevels.All);
public static void Enter(string entryPoint)
{
TraceInformation("enter {0}", entryPoint);
}
public static void Exit(string entryPoint)
{
TraceInformation("exit {0}", entryPoint);
}
public static void TraceInformation(string message, params object[] param)
{
Trace.TraceInformation(message, param);
}
public static void TraceWarning(string message, params object[] param)
{
Trace.TraceEvent(TraceEventType.Warning, -1, message, param);
}
public static void TraceError(string message, int id, params object[] param)
{
Trace.TraceEvent(TraceEventType.Error, id, message, param);
}
public static void TraceError(string message, Exception ex)
{
Trace.TraceEvent(TraceEventType.Error, ex.HResult, "{0}, {1}", message, ex.Message);
}
public static void TraceError(string message)
{
Trace.TraceEvent(TraceEventType.Error, message.GetHashCode(), message);
}
public static void TraceError(string message, params object[] param)
{
TraceError(message, -2, param);
}
static Tracer()
{
SourceSwitch sw = new SourceSwitch(SwitchName, SwitchName);
sw.Level = SourceLevels.All;
Trace.Switch = sw;
}
}
}