##// END OF EJS Templates
minor changes
cin -
r195:ea485487a424 v2
parent child
Show More
@@ -30,11 +30,11
30 30 else if (m_ownership)
31 31 m_current = LogicalOperation.EMPTY;
32 32 else {
33 TraceLog.TraceWarning("DetachLogicalOperation can't be applied in the current context");
33 TraceLog.TraceWarning("DetachLogicalOperation can't be performed in the current context");
34 34 detached = LogicalOperation.EMPTY;
35 35 }
36 36 } else {
37 TraceLog.TraceWarning("DetachLogicalOperation can't be applied in the current context");
37 TraceLog.TraceWarning("DetachLogicalOperation can't be performed in the current context");
38 38 }
39 39
40 40 return detached;
@@ -50,7 +50,7
50 50 m_ownership = false;
51 51 }
52 52 } else {
53 TraceLog.TraceWarning("EndLogicalOperation can't be applied in the current context");
53 TraceLog.TraceWarning("EndLogicalOperation can't be performed in the current context");
54 54 }
55 55 return current;
56 56 }
@@ -56,9 +56,8 namespace Implab.Diagnostics {
56 56 StartLogicalOperation(String.Empty);
57 57 }
58 58
59 public void EndLogicalOperation() {
60 var op = m_current.EndLogicalOperation();
61 LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(TraceEventType.OperationCompleted, String.Format("-{0} : {1}ms",op.Name, op.Duration)));
59 public LogicalOperation EndLogicalOperation() {
60 return m_current.EndLogicalOperation();
62 61 }
63 62
64 63 public LogicalOperation DetachLogicalOperation() {
@@ -12,18 +12,36 namespace Implab.Diagnostics {
12 12 private set;
13 13 }
14 14
15 public TraceEvent(TraceEventType type, string message) {
15 /// <summary>
16 /// The logical operation this event belongs to.
17 /// </summary>
18 public LogicalOperation Operation {
19 get;
20 private set;
21 }
22
23 /// <summary>
24 /// Gets the time offset in milliseconds from the start of the operation, if the operation is not specified the value is zero.
25 /// </summary>
26 public int OperationTime {
27 get;
28 private set;
29 }
30
31 public TraceEvent(LogicalOperation operation, TraceEventType type, string message) {
16 32 EventType = type;
17 33 Message = message;
34 Operation = operation;
35 if (operation != null)
36 OperationTime = operation.Duration;
18 37 }
19 38
20 39 public override string ToString() {
21 /*return EventType == TraceEventType.Information ? Message : String.Format("{0}: {1}", EventType, Message);*/
22 40 return Message;
23 41 }
24 42
25 public static TraceEvent Create(TraceEventType type, string format, params object[] args) {
26 return new TraceEvent(type, format == null ? String.Empty : String.Format(format, args));
43 public static TraceEvent Create(LogicalOperation operation, TraceEventType type, string format, params object[] args) {
44 return new TraceEvent(operation, type, format == null ? String.Empty : String.Format(format, args));
27 45 }
28 46 }
29 47 }
@@ -7,31 +7,51 using System.Threading.Tasks;
7 7
8 8 namespace Implab.Diagnostics {
9 9 /// <summary>
10 /// Класс для ΠΏΡƒΠ±Π»ΠΈΠΊΠ°Ρ†ΠΈΠΈ событий выполнСния ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹, события ΠΏΡƒΠ±Π»ΠΈΠΊΡƒΡŽΡ‚ΡΡ Ρ‡Π΅Ρ€Π΅Π· <see cref="LogChannel{TraceEvent}"/>.
11 /// Π–ΡƒΡ€Π½Π°Π» трассировки ΠΎΡ‚Ρ€Π°ΠΆΠ°Π΅Ρ‚ логичСский Ρ…ΠΎΠ΄ выполнСния ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹ ΠΈ сущСствуСт всСгда, ΠΏΠΎΡΠΊΠΎΠ»ΡŒΠΊΡƒ тСсно связан с
12 /// контСкстом трассировки.
10 /// This class is used to trace a logical flow of the application, it publishes events to the default <see cref="TraceEvent"/> channel.
13 11 /// </summary>
14 12 public static class TraceLog {
13 /// <summary>
14 /// Starts the logical operation nested to the current operation nested to the current one.
15 /// </summary>
15 16 [Conditional("TRACE")]
16 17 public static void StartLogicalOperation() {
17 18 TraceContext.Instance.StartLogicalOperation();
19
18 20 }
19 21
22 /// <summary>
23 /// Starts the logical operation with the specified name, this name is usefull in logs.
24 /// </summary>
25 /// <param name="name">Name.</param>
20 26 [Conditional("TRACE")]
21 27 public static void StartLogicalOperation(string name) {
22 28 TraceContext.Instance.StartLogicalOperation(name);
23 29 }
24 30
31 /// <summary>
32 /// Ends the logical operation and restores the previous one.
33 /// </summary>
25 34 [Conditional("TRACE")]
26 35 public static void EndLogicalOperation() {
27 TraceContext.Instance.EndLogicalOperation();
36 var op = TraceContext.Instance.EndLogicalOperation();
37 LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(TraceEventType.OperationCompleted, String.Format("-{0} : {1}ms",op.Name, op.Duration)));
28 38 }
29 39
40 /// <summary>
41 /// Writes an informational message.
42 /// </summary>
43 /// <param name="format">Format.</param>
44 /// <param name="arguments">Arguments.</param>
30 45 [Conditional("TRACE")]
31 46 public static void TraceInformation(string format, params object[] arguments) {
32 47 LogChannel<TraceEvent>.Default.LogEvent(TraceEvent.Create(TraceEventType.Information, format, arguments));
33 48 }
34 49
50 /// <summary>
51 /// Writes a warning message.
52 /// </summary>
53 /// <param name="format">Format.</param>
54 /// <param name="arguments">Arguments.</param>
35 55 [Conditional("TRACE")]
36 56 public static void TraceWarning(string format, params object[] arguments) {
37 57 LogChannel<TraceEvent>.Default.LogEvent(TraceEvent.Create(TraceEventType.Warning, format, arguments));
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

ok, latest stable version should be in default

You need to be logged in to leave comments. Login now