annotate Implab/Diagnostics/TraceEvent.cs @ 209:a867536c68fc v2

Bound promise to CancellationToken Added new states to ExecutionSate enum. Added Safe.Guard() method to handle cleanup of the result of the promise
author cin
date Wed, 16 Nov 2016 03:06:08 +0300
parents ea485487a424
children cc1baf7c8bd9
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
313f708a50e9 improved log concept
cin
parents:
diff changeset
3 namespace Implab.Diagnostics {
313f708a50e9 improved log concept
cin
parents:
diff changeset
4 public class TraceEvent {
313f708a50e9 improved log concept
cin
parents:
diff changeset
5 public string Message {
313f708a50e9 improved log concept
cin
parents:
diff changeset
6 get;
313f708a50e9 improved log concept
cin
parents:
diff changeset
7 private set;
313f708a50e9 improved log concept
cin
parents:
diff changeset
8 }
313f708a50e9 improved log concept
cin
parents:
diff changeset
9
313f708a50e9 improved log concept
cin
parents:
diff changeset
10 public TraceEventType EventType {
313f708a50e9 improved log concept
cin
parents:
diff changeset
11 get;
313f708a50e9 improved log concept
cin
parents:
diff changeset
12 private set;
313f708a50e9 improved log concept
cin
parents:
diff changeset
13 }
313f708a50e9 improved log concept
cin
parents:
diff changeset
14
195
ea485487a424 minor changes
cin
parents: 133
diff changeset
15 /// <summary>
ea485487a424 minor changes
cin
parents: 133
diff changeset
16 /// The logical operation this event belongs to.
ea485487a424 minor changes
cin
parents: 133
diff changeset
17 /// </summary>
ea485487a424 minor changes
cin
parents: 133
diff changeset
18 public LogicalOperation Operation {
ea485487a424 minor changes
cin
parents: 133
diff changeset
19 get;
ea485487a424 minor changes
cin
parents: 133
diff changeset
20 private set;
ea485487a424 minor changes
cin
parents: 133
diff changeset
21 }
ea485487a424 minor changes
cin
parents: 133
diff changeset
22
ea485487a424 minor changes
cin
parents: 133
diff changeset
23 /// <summary>
ea485487a424 minor changes
cin
parents: 133
diff changeset
24 /// Gets the time offset in milliseconds from the start of the operation, if the operation is not specified the value is zero.
ea485487a424 minor changes
cin
parents: 133
diff changeset
25 /// </summary>
ea485487a424 minor changes
cin
parents: 133
diff changeset
26 public int OperationTime {
ea485487a424 minor changes
cin
parents: 133
diff changeset
27 get;
ea485487a424 minor changes
cin
parents: 133
diff changeset
28 private set;
ea485487a424 minor changes
cin
parents: 133
diff changeset
29 }
ea485487a424 minor changes
cin
parents: 133
diff changeset
30
ea485487a424 minor changes
cin
parents: 133
diff changeset
31 public TraceEvent(LogicalOperation operation, TraceEventType type, string message) {
36
313f708a50e9 improved log concept
cin
parents:
diff changeset
32 EventType = type;
313f708a50e9 improved log concept
cin
parents:
diff changeset
33 Message = message;
195
ea485487a424 minor changes
cin
parents: 133
diff changeset
34 Operation = operation;
ea485487a424 minor changes
cin
parents: 133
diff changeset
35 if (operation != null)
ea485487a424 minor changes
cin
parents: 133
diff changeset
36 OperationTime = operation.Duration;
36
313f708a50e9 improved log concept
cin
parents:
diff changeset
37 }
313f708a50e9 improved log concept
cin
parents:
diff changeset
38
40
fe33f4e02ad5 improved tracing
cin
parents: 36
diff changeset
39 public override string ToString() {
133
cin
parents: 93
diff changeset
40 return Message;
40
fe33f4e02ad5 improved tracing
cin
parents: 36
diff changeset
41 }
fe33f4e02ad5 improved tracing
cin
parents: 36
diff changeset
42
195
ea485487a424 minor changes
cin
parents: 133
diff changeset
43 public static TraceEvent Create(LogicalOperation operation, TraceEventType type, string format, params object[] args) {
ea485487a424 minor changes
cin
parents: 133
diff changeset
44 return new TraceEvent(operation, type, format == null ? String.Empty : String.Format(format, args));
36
313f708a50e9 improved log concept
cin
parents:
diff changeset
45 }
313f708a50e9 improved log concept
cin
parents:
diff changeset
46 }
313f708a50e9 improved log concept
cin
parents:
diff changeset
47 }