forked from gitextensions/gitextensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TraceWriter.cs
69 lines (55 loc) · 1.86 KB
/
TraceWriter.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
60
61
62
63
64
65
66
67
68
using System.Diagnostics;
using System.Reflection;
/// <summary>
/// Summary description for TraceWriter.
/// </summary>
internal static class TraceWriter
{
public static TraceSwitch Switch = new TraceSwitch(Assembly.GetAssembly(typeof(TraceWriter)).GetName().Name, "Trace Helper Switch");
public static void TraceError(string format, params object[] args)
{
if (Switch.TraceError)
Trace.WriteLine(string.Format(format, args), GetCallingMethod(new StackTrace(1)));
}
public static void TraceError(string value)
{
if (Switch.TraceError)
Trace.WriteLine(value, GetCallingMethod(new StackTrace(1)));
}
public static void TraceInfo(string format, params object[] args)
{
if (Switch.TraceInfo)
Trace.WriteLine(string.Format(format, args), GetCallingMethod(new StackTrace(1)));
}
public static void TraceInfo(string value)
{
if (Switch.TraceInfo)
Trace.WriteLine(value, GetCallingMethod(new StackTrace(1)));
}
public static void TraceWarning(string format, params object[] args)
{
if (Switch.TraceWarning)
Trace.WriteLine(string.Format(format, args), GetCallingMethod(new StackTrace(1)));
}
public static void TraceWarning(string value)
{
if (Switch.TraceWarning)
Trace.WriteLine(value, GetCallingMethod(new StackTrace(1))); }
public static void TraceVerbose(string format, params object[] args)
{
if (Switch.TraceVerbose)
Trace.WriteLine(string.Format(format, args), GetCallingMethod(new StackTrace(1)));
}
public static void TraceVerbose(string value)
{
if (Switch.TraceVerbose)
Trace.WriteLine(value, GetCallingMethod(new StackTrace(1)));
}
private static string GetCallingMethod(StackTrace stack)
{
StackFrame frame = stack.GetFrame(0);
string className = frame.GetMethod().DeclaringType.ToString();
string functionName = frame.GetMethod().Name;
return string.Format("{0}.{1}", className, functionName);
}
}