annotate Implab/Diagnostics/Trace.cs @ 214:9c32ef39b851 v2

Added the time delta column to the interactive trace listener
author cin
date Fri, 14 Apr 2017 15:57:23 +0300
parents a01d9df88d74
children babe55c34931
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
212
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
1 using System;
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
2 using System.Collections.Generic;
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
3 using System.Diagnostics;
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
4 using System.Linq;
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
5 using System.Text;
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
6 using System.Threading.Tasks;
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
7
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
8 namespace Implab.Diagnostics {
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
9 public static class Trace<T> {
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
10
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
11 readonly static LogChannel<TraceEvent> _channel = new LogChannel<TraceEvent>(typeof(T).Name);
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
12
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
13 public static LogChannel<TraceEvent> Channel {
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
14 get { return _channel; }
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
15 }
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
16
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
17 /// <summary>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
18 /// Starts the logical operation nested to the current operation nested to the current one.
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
19 /// </summary>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
20 [Conditional("TRACE")]
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
21 public static void StartLogicalOperation() {
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
22 TraceContext.Instance.StartLogicalOperation();
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
23
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
24 }
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
25
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
26 /// <summary>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
27 /// Starts the logical operation with the specified name, this name is usefull in logs.
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
28 /// </summary>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
29 /// <param name="name">Name.</param>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
30 [Conditional("TRACE")]
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
31 public static void StartLogicalOperation(string name) {
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
32 TraceContext.Instance.StartLogicalOperation(name);
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
33 }
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
34
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
35 /// <summary>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
36 /// Ends the logical operation and restores the previous one.
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
37 /// </summary>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
38 [Conditional("TRACE")]
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
39 public static void EndLogicalOperation() {
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
40 var op = TraceContext.Instance.EndLogicalOperation();
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
41 LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(op, TraceEventType.OperationCompleted, String.Format("-{0} : {1}ms", op.Name, op.Duration)));
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
42 }
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
43
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
44 /// <summary>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
45 /// Writes an informational message.
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
46 /// </summary>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
47 /// <param name="format">Format.</param>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
48 /// <param name="arguments">Arguments.</param>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
49 [Conditional("TRACE")]
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
50 public static void Log(string format, params object[] arguments) {
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
51 Channel.LogEvent(TraceEvent.Create(TraceContext.Instance.CurrentOperation, TraceEventType.Information, format, arguments));
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
52 }
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
53
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
54 /// <summary>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
55 /// Writes a warning message.
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
56 /// </summary>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
57 /// <param name="format">Format.</param>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
58 /// <param name="arguments">Arguments.</param>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
59 [Conditional("TRACE")]
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
60 public static void Warn(string format, params object[] arguments) {
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
61 Channel.LogEvent(TraceEvent.Create(TraceContext.Instance.CurrentOperation, TraceEventType.Warning, format, arguments));
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
62 }
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
63
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
64 [Conditional("TRACE")]
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
65 public static void Error(string format, params object[] arguments) {
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
66 Channel.LogEvent(TraceEvent.Create(TraceContext.Instance.CurrentOperation, TraceEventType.Error, format, arguments));
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
67 }
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
68
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
69 [Conditional("TRACE")]
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
70 public static void Error(Exception err) {
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
71 Error("{0}", err);
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
72 }
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
73 }
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
74 }