annotate Implab/Diagnostics/TraceLog.cs @ 237:f2150c16b476 v2

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