comparison Implab/Diagnostics/Trace.cs @ 253:34df34841225 v3 v3.0.1-beta

Implab.Diagnostics drafts
author cin
date Mon, 12 Feb 2018 17:03:37 +0300
parents 6f4630d0bcd9
children b00441e04738
comparison
equal deleted inserted replaced
252:6f4630d0bcd9 253:34df34841225
27 /// Starts the logical operation with the specified name, this name is usefull in logs. 27 /// Starts the logical operation with the specified name, this name is usefull in logs.
28 /// </summary> 28 /// </summary>
29 /// <param name="name">Name.</param> 29 /// <param name="name">Name.</param>
30 [Conditional("TRACE")] 30 [Conditional("TRACE")]
31 public static void StartLogicalOperation(string name) { 31 public static void StartLogicalOperation(string name) {
32 Trace.CorrelationManager.StartLogicalOperation(); 32 Trace.CorrelationManager.StartLogicalOperation(name);
33 } 33 }
34 34
35 /// <summary> 35 /// <summary>
36 /// Ends the logical operation and restores the previous one. 36 /// Ends the logical operation and restores the previous one.
37 /// </summary> 37 /// </summary>
45 /// </summary> 45 /// </summary>
46 /// <param name="format">Format.</param> 46 /// <param name="format">Format.</param>
47 /// <param name="arguments">Arguments.</param> 47 /// <param name="arguments">Arguments.</param>
48 [Conditional("TRACE")] 48 [Conditional("TRACE")]
49 public static void Log(string format, params object[] arguments) { 49 public static void Log(string format, params object[] arguments) {
50 TraceSource.TraceEvent(TraceEventType.Information, 1, format, arguments); 50 TraceSource.TraceEvent(TraceEventType.Information, 0, format, arguments);
51 } 51 }
52 52
53 /// <summary> 53 /// <summary>
54 /// Writes a warning message. 54 /// Writes a warning message.
55 /// </summary> 55 /// </summary>
56 /// <param name="format">Format.</param> 56 /// <param name="format">Format.</param>
57 /// <param name="arguments">Arguments.</param> 57 /// <param name="arguments">Arguments.</param>
58 [Conditional("TRACE")] 58 [Conditional("TRACE")]
59 public static void Warn(string format, params object[] arguments) { 59 public static void Warn(string format, params object[] arguments) {
60 TraceSource.TraceEvent(TraceEventType.Warning, 1, format, arguments); 60 TraceSource.TraceEvent(TraceEventType.Warning, 0, format, arguments);
61 } 61 }
62 62
63 [Conditional("TRACE")] 63 [Conditional("TRACE")]
64 public static void Error(string format, params object[] arguments) { 64 public static void Error(string format, params object[] arguments) {
65 TraceSource.TraceEvent(TraceEventType.Error, 1, format, arguments); 65 TraceSource.TraceEvent(TraceEventType.Error, 0, format, arguments);
66 } 66 }
67 67
68 [Conditional("TRACE")] 68 [Conditional("TRACE")]
69 public static void Error(Exception err) { 69 public static void Error(Exception err) {
70 TraceSource.TraceData(TraceEventType.Error, 1, err); 70 TraceSource.TraceData(TraceEventType.Error, 0, err);
71 }
72
73 /// <summary>
74 /// This method save the current activity, and transfers to the specified activity,
75 /// emits <see cref="TraceEventType.Start"/> and returns a scope of the new
76 /// activity.
77 /// </summary>
78 /// <param name="activityName">The name of the new activity/</param>
79 /// <param name="activityId">The identifier of the activity to which
80 /// the control will be transferred</param>
81 /// <returns>A scope of the new activity, dispose it to transfer
82 /// the control back to the original activity.</returns>
83 public static ActivityScope TransferActivity(string activityName, Guid activityId) {
84 var prev = Trace.CorrelationManager.ActivityId;
85
86 TraceSource.TraceTransfer(0, "Transfer", activityId);
87 Trace.CorrelationManager.ActivityId = activityId;
88 TraceSource.TraceEvent(TraceEventType.Start, 0, activityName);
89
90 return new ActivityScope(TraceSource, prev, 0, activityName);
91 }
92
93 /// <summary>
94 /// Emits <see cref="TraceEventType.Start"/> and returns a scope of the
95 /// activity.
96 /// </summary>
97 /// <param name="activityName">The name of the activity to start</param>
98 /// <returns>A scope of the new activity, dispose it to emit
99 /// <see cref="TraceEventType.Stop"/> for the current activity.</returns>
100 public static ActivityScope StartActivity(string activityName) {
101 if (Trace.CorrelationManager.ActivityId == Guid.Empty)
102 Trace.CorrelationManager.ActivityId = Guid.NewGuid();
103
104 var prev = Trace.CorrelationManager.ActivityId;
105
106 TraceSource.TraceEvent(TraceEventType.Start, 0, activityName);
107 return new ActivityScope(TraceSource, prev, 0, activityName);
108 }
109
110 /// <summary>
111 /// Creates new <see cref="LogicalOperation(string)"/> and calls
112 /// to <see cref="CorrelationManager.StartLogicalOperation(object)"/>
113 /// passing the created operation as identity. Calls
114 /// <see cref="TraceSource.TraceData(TraceEventType, int, object)"/>
115 /// to notify listeners on operation start.
116 /// </summary>
117 /// <param name="name">The name of the logical operation.</param>
118 /// <returns>Logical operation scope, disposing it will stop
119 /// logical operation and notify trace listeners.</returns>
120 public static LogicalOperationScope LogicalOperation(string name) {
121 var operation = new LogicalOperation(name);
122 TraceSource.TraceData(TraceEventType.Information, TraceEventCodes.StartLogicalOperation, operation);
123 Trace.CorrelationManager.StartLogicalOperation(operation);
124 return new LogicalOperationScope(TraceSource, operation);
71 } 125 }
72 } 126 }
73 } 127 }