changeset 195:ea485487a424 v2

minor changes
author cin
date Wed, 04 May 2016 12:28:08 +0300
parents d45bdf510514
children 43b1017ce100
files Implab/Diagnostics/OperationContext.cs Implab/Diagnostics/TraceContext.cs Implab/Diagnostics/TraceEvent.cs Implab/Diagnostics/TraceLog.cs
diffstat 4 files changed, 51 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/Implab/Diagnostics/OperationContext.cs	Mon Apr 25 15:18:56 2016 +0300
+++ b/Implab/Diagnostics/OperationContext.cs	Wed May 04 12:28:08 2016 +0300
@@ -30,11 +30,11 @@
                 else if (m_ownership)
                     m_current = LogicalOperation.EMPTY;
                 else {
-                    TraceLog.TraceWarning("DetachLogicalOperation can't be applied in the current context");
+                    TraceLog.TraceWarning("DetachLogicalOperation can't be performed in the current context");
                     detached = LogicalOperation.EMPTY;
                 }
             } else {
-                TraceLog.TraceWarning("DetachLogicalOperation can't be applied in the current context");
+                TraceLog.TraceWarning("DetachLogicalOperation can't be performed in the current context");
             }
 
             return detached;
@@ -50,7 +50,7 @@
                     m_ownership = false;
                 }
             } else {
-                TraceLog.TraceWarning("EndLogicalOperation can't be applied in the current context");
+                TraceLog.TraceWarning("EndLogicalOperation can't be performed in the current context");
             }
             return current;
         }
--- a/Implab/Diagnostics/TraceContext.cs	Mon Apr 25 15:18:56 2016 +0300
+++ b/Implab/Diagnostics/TraceContext.cs	Wed May 04 12:28:08 2016 +0300
@@ -56,9 +56,8 @@
             StartLogicalOperation(String.Empty);
         }
 
-        public void EndLogicalOperation() {
-            var op = m_current.EndLogicalOperation();
-            LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(TraceEventType.OperationCompleted, String.Format("-{0} : {1}ms",op.Name, op.Duration)));
+        public LogicalOperation EndLogicalOperation() {
+            return m_current.EndLogicalOperation();
         }
 
         public LogicalOperation DetachLogicalOperation() {
--- a/Implab/Diagnostics/TraceEvent.cs	Mon Apr 25 15:18:56 2016 +0300
+++ b/Implab/Diagnostics/TraceEvent.cs	Wed May 04 12:28:08 2016 +0300
@@ -12,18 +12,36 @@
             private set;
         }
 
-        public TraceEvent(TraceEventType type, string message) {
+        /// <summary>
+        /// The logical operation this event belongs to.
+        /// </summary>
+        public LogicalOperation Operation {
+            get;
+            private set;
+        }
+
+        /// <summary>
+        /// Gets the time offset in milliseconds from the start of the operation, if the operation is not specified the value is zero.
+        /// </summary>
+        public int OperationTime {
+            get;
+            private set;
+        }
+
+        public TraceEvent(LogicalOperation operation, TraceEventType type, string message) {
             EventType = type;
             Message = message;
+            Operation = operation;
+            if (operation != null)
+                OperationTime = operation.Duration;
         }
 
         public override string ToString() {
-            /*return EventType == TraceEventType.Information ? Message : String.Format("{0}: {1}", EventType, Message);*/
             return Message;
         }
 
-        public static TraceEvent Create(TraceEventType type, string format, params object[] args) {
-            return new TraceEvent(type, format == null ? String.Empty : String.Format(format, args));
+        public static TraceEvent Create(LogicalOperation operation, TraceEventType type, string format, params object[] args) {
+            return new TraceEvent(operation, type, format == null ? String.Empty : String.Format(format, args));
         }
     }
 }
--- a/Implab/Diagnostics/TraceLog.cs	Mon Apr 25 15:18:56 2016 +0300
+++ b/Implab/Diagnostics/TraceLog.cs	Wed May 04 12:28:08 2016 +0300
@@ -7,31 +7,51 @@
 
 namespace Implab.Diagnostics {
     /// <summary>
-    /// Класс для публикации событий выполнения программы, события публикуются через <see cref="LogChannel{TraceEvent}"/>.
-    /// Журнал трассировки отражает логический ход выполнения программы и существует всегда, поскольку тесно связан с 
-    /// контекстом трассировки.
+    /// This class is used to trace a logical flow of the application, it publishes events to the default <see cref="TraceEvent"/> channel.
     /// </summary>
     public static class TraceLog {
+        /// <summary>
+        /// Starts the logical operation nested to the current operation nested to the current one.
+        /// </summary>
         [Conditional("TRACE")]
         public static void StartLogicalOperation() {
             TraceContext.Instance.StartLogicalOperation();
+
         }
 
+        /// <summary>
+        /// Starts the logical operation with the specified name, this name is usefull in logs.
+        /// </summary>
+        /// <param name="name">Name.</param>
         [Conditional("TRACE")]
         public static void StartLogicalOperation(string name) {
             TraceContext.Instance.StartLogicalOperation(name);
         }
 
+        /// <summary>
+        /// Ends the logical operation and restores the previous one.
+        /// </summary>
         [Conditional("TRACE")]
         public static void EndLogicalOperation() {
-            TraceContext.Instance.EndLogicalOperation();
+            var op = TraceContext.Instance.EndLogicalOperation();
+            LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(TraceEventType.OperationCompleted, String.Format("-{0} : {1}ms",op.Name, op.Duration)));
         }
 
+        /// <summary>
+        /// Writes an informational message.
+        /// </summary>
+        /// <param name="format">Format.</param>
+        /// <param name="arguments">Arguments.</param>
         [Conditional("TRACE")]
         public static void TraceInformation(string format, params object[] arguments) {
             LogChannel<TraceEvent>.Default.LogEvent(TraceEvent.Create(TraceEventType.Information, format, arguments));
         }
 
+        /// <summary>
+        /// Writes a warning message.
+        /// </summary>
+        /// <param name="format">Format.</param>
+        /// <param name="arguments">Arguments.</param>
         [Conditional("TRACE")]
         public static void TraceWarning(string format, params object[] arguments) {
             LogChannel<TraceEvent>.Default.LogEvent(TraceEvent.Create(TraceEventType.Warning, format, arguments));