36
|
1 using System;
|
|
2 using System.Collections.Generic;
|
|
3 using System.Diagnostics;
|
|
4 using System.Linq;
|
|
5 using System.Text;
|
|
6 using System.Threading.Tasks;
|
|
7
|
|
8 namespace Implab.Diagnostics {
|
|
9 /// <summary>
|
195
|
10 /// This class is used to trace a logical flow of the application, it publishes events to the default <see cref="TraceEvent"/> channel.
|
36
|
11 /// </summary>
|
|
12 public static class TraceLog {
|
195
|
13 /// <summary>
|
|
14 /// Starts the logical operation nested to the current operation nested to the current one.
|
|
15 /// </summary>
|
36
|
16 [Conditional("TRACE")]
|
|
17 public static void StartLogicalOperation() {
|
92
|
18 TraceContext.Instance.StartLogicalOperation();
|
195
|
19
|
36
|
20 }
|
|
21
|
195
|
22 /// <summary>
|
|
23 /// Starts the logical operation with the specified name, this name is usefull in logs.
|
|
24 /// </summary>
|
|
25 /// <param name="name">Name.</param>
|
36
|
26 [Conditional("TRACE")]
|
|
27 public static void StartLogicalOperation(string name) {
|
92
|
28 TraceContext.Instance.StartLogicalOperation(name);
|
36
|
29 }
|
|
30
|
195
|
31 /// <summary>
|
|
32 /// Ends the logical operation and restores the previous one.
|
|
33 /// </summary>
|
36
|
34 [Conditional("TRACE")]
|
|
35 public static void EndLogicalOperation() {
|
195
|
36 var op = TraceContext.Instance.EndLogicalOperation();
|
|
37 LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(TraceEventType.OperationCompleted, String.Format("-{0} : {1}ms",op.Name, op.Duration)));
|
52
|
38 }
|
|
39
|
195
|
40 /// <summary>
|
|
41 /// Writes an informational message.
|
|
42 /// </summary>
|
|
43 /// <param name="format">Format.</param>
|
|
44 /// <param name="arguments">Arguments.</param>
|
52
|
45 [Conditional("TRACE")]
|
36
|
46 public static void TraceInformation(string format, params object[] arguments) {
|
|
47 LogChannel<TraceEvent>.Default.LogEvent(TraceEvent.Create(TraceEventType.Information, format, arguments));
|
|
48 }
|
|
49
|
195
|
50 /// <summary>
|
|
51 /// Writes a warning message.
|
|
52 /// </summary>
|
|
53 /// <param name="format">Format.</param>
|
|
54 /// <param name="arguments">Arguments.</param>
|
36
|
55 [Conditional("TRACE")]
|
|
56 public static void TraceWarning(string format, params object[] arguments) {
|
|
57 LogChannel<TraceEvent>.Default.LogEvent(TraceEvent.Create(TraceEventType.Warning, format, arguments));
|
|
58 }
|
|
59
|
|
60 [Conditional("TRACE")]
|
|
61 public static void TraceError(string format, params object[] arguments) {
|
|
62 LogChannel<TraceEvent>.Default.LogEvent(TraceEvent.Create(TraceEventType.Error, format, arguments));
|
|
63 }
|
|
64
|
|
65 [Conditional("TRACE")]
|
|
66 public static void TraceError(Exception err) {
|
|
67 TraceError("{0}", err);
|
|
68 }
|
|
69 }
|
|
70 }
|