annotate Implab/Diagnostics/Trace.cs @ 225:8222a2ab3ab7 v2

JSONXmlReaderFixed fixed boolean values handling
author cin
date Wed, 23 Aug 2017 02:38:02 +0300
parents babe55c34931
children 6f4630d0bcd9
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) {
218
babe55c34931 Trace logical operations in the correct channel
cin
parents: 212
diff changeset
32 Channel.LogEvent(new TraceEvent(TraceContext.Instance.CurrentOperation, TraceEventType.OperationStarted, name));
212
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
33 TraceContext.Instance.StartLogicalOperation(name);
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
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
36 /// <summary>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
37 /// 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
38 /// </summary>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
39 [Conditional("TRACE")]
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
40 public static void EndLogicalOperation() {
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
41 var op = TraceContext.Instance.EndLogicalOperation();
218
babe55c34931 Trace logical operations in the correct channel
cin
parents: 212
diff changeset
42 Channel.LogEvent(new TraceEvent(op, TraceEventType.OperationCompleted, String.Format("-{0} : {1}ms", op.Name, op.Duration)));
212
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
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
45 /// <summary>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
46 /// Writes an informational message.
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
47 /// </summary>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
48 /// <param name="format">Format.</param>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
49 /// <param name="arguments">Arguments.</param>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
50 [Conditional("TRACE")]
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
51 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
52 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
53 }
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
54
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
55 /// <summary>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
56 /// Writes a warning message.
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
57 /// </summary>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
58 /// <param name="format">Format.</param>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
59 /// <param name="arguments">Arguments.</param>
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
60 [Conditional("TRACE")]
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
61 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
62 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
63 }
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
64
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
65 [Conditional("TRACE")]
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
66 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
67 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
68 }
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
69
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
70 [Conditional("TRACE")]
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
71 public static void Error(Exception err) {
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
72 Error("{0}", err);
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 }
a01d9df88d74 Added class Trace<T> to manage channels for individual classes, if SomeClass
cin
parents:
diff changeset
75 }