diff --git a/Implab/Diagnostics/OperationContext.cs b/Implab/Diagnostics/OperationContext.cs --- a/Implab/Diagnostics/OperationContext.cs +++ b/Implab/Diagnostics/OperationContext.cs @@ -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; } diff --git a/Implab/Diagnostics/TraceContext.cs b/Implab/Diagnostics/TraceContext.cs --- a/Implab/Diagnostics/TraceContext.cs +++ b/Implab/Diagnostics/TraceContext.cs @@ -56,9 +56,8 @@ namespace Implab.Diagnostics { StartLogicalOperation(String.Empty); } - public void EndLogicalOperation() { - var op = m_current.EndLogicalOperation(); - LogChannel.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() { diff --git a/Implab/Diagnostics/TraceEvent.cs b/Implab/Diagnostics/TraceEvent.cs --- a/Implab/Diagnostics/TraceEvent.cs +++ b/Implab/Diagnostics/TraceEvent.cs @@ -12,18 +12,36 @@ namespace Implab.Diagnostics { private set; } - public TraceEvent(TraceEventType type, string message) { + /// + /// The logical operation this event belongs to. + /// + public LogicalOperation Operation { + get; + private set; + } + + /// + /// Gets the time offset in milliseconds from the start of the operation, if the operation is not specified the value is zero. + /// + 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)); } } } diff --git a/Implab/Diagnostics/TraceLog.cs b/Implab/Diagnostics/TraceLog.cs --- a/Implab/Diagnostics/TraceLog.cs +++ b/Implab/Diagnostics/TraceLog.cs @@ -7,31 +7,51 @@ using System.Threading.Tasks; namespace Implab.Diagnostics { /// - /// Класс для публикации событий выполнения программы, события публикуются через . - /// Журнал трассировки отражает логический ход выполнения программы и существует всегда, поскольку тесно связан с - /// контекстом трассировки. + /// This class is used to trace a logical flow of the application, it publishes events to the default channel. /// public static class TraceLog { + /// + /// Starts the logical operation nested to the current operation nested to the current one. + /// [Conditional("TRACE")] public static void StartLogicalOperation() { TraceContext.Instance.StartLogicalOperation(); + } + /// + /// Starts the logical operation with the specified name, this name is usefull in logs. + /// + /// Name. [Conditional("TRACE")] public static void StartLogicalOperation(string name) { TraceContext.Instance.StartLogicalOperation(name); } + /// + /// Ends the logical operation and restores the previous one. + /// [Conditional("TRACE")] public static void EndLogicalOperation() { - TraceContext.Instance.EndLogicalOperation(); + var op = TraceContext.Instance.EndLogicalOperation(); + LogChannel.Default.LogEvent(new TraceEvent(TraceEventType.OperationCompleted, String.Format("-{0} : {1}ms",op.Name, op.Duration))); } + /// + /// Writes an informational message. + /// + /// Format. + /// Arguments. [Conditional("TRACE")] public static void TraceInformation(string format, params object[] arguments) { LogChannel.Default.LogEvent(TraceEvent.Create(TraceEventType.Information, format, arguments)); } + /// + /// Writes a warning message. + /// + /// Format. + /// Arguments. [Conditional("TRACE")] public static void TraceWarning(string format, params object[] arguments) { LogChannel.Default.LogEvent(TraceEvent.Create(TraceEventType.Warning, format, arguments));