# HG changeset patch # User cin # Date 1491296645 -10800 # Node ID a01d9df88d74c741fdf3def358092664e54e23e9 # Parent 3eb3255d8cc5fd3afe82cac44fc5fe7fda6d5fc8 Added class Trace to manage channels for individual classes, if SomeClass uses Trace it sould be marked with TraceSourceAttribute diff -r 3eb3255d8cc5 -r a01d9df88d74 Implab/Diagnostics/Trace.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Implab/Diagnostics/Trace.cs Tue Apr 04 12:04:05 2017 +0300 @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Implab.Diagnostics { + public static class Trace { + + readonly static LogChannel _channel = new LogChannel(typeof(T).Name); + + public static LogChannel Channel { + get { return _channel; } + } + + /// + /// 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() { + var op = TraceContext.Instance.EndLogicalOperation(); + LogChannel.Default.LogEvent(new TraceEvent(op, TraceEventType.OperationCompleted, String.Format("-{0} : {1}ms", op.Name, op.Duration))); + } + + /// + /// Writes an informational message. + /// + /// Format. + /// Arguments. + [Conditional("TRACE")] + public static void Log(string format, params object[] arguments) { + Channel.LogEvent(TraceEvent.Create(TraceContext.Instance.CurrentOperation, TraceEventType.Information, format, arguments)); + } + + /// + /// Writes a warning message. + /// + /// Format. + /// Arguments. + [Conditional("TRACE")] + public static void Warn(string format, params object[] arguments) { + Channel.LogEvent(TraceEvent.Create(TraceContext.Instance.CurrentOperation, TraceEventType.Warning, format, arguments)); + } + + [Conditional("TRACE")] + public static void Error(string format, params object[] arguments) { + Channel.LogEvent(TraceEvent.Create(TraceContext.Instance.CurrentOperation, TraceEventType.Error, format, arguments)); + } + + [Conditional("TRACE")] + public static void Error(Exception err) { + Error("{0}", err); + } + } +} diff -r 3eb3255d8cc5 -r a01d9df88d74 Implab/Diagnostics/TraceSourceAttribute.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Implab/Diagnostics/TraceSourceAttribute.cs Tue Apr 04 12:04:05 2017 +0300 @@ -0,0 +1,10 @@ +using System; + +namespace Implab.Diagnostics { + /// + /// Used to mark class which uses class to trace it's events + /// + [AttributeUsage(AttributeTargets.Class)] + public class TraceSourceAttribute : Attribute { + } +} diff -r 3eb3255d8cc5 -r a01d9df88d74 Implab/Implab.csproj --- a/Implab/Implab.csproj Tue Mar 21 17:29:13 2017 +0300 +++ b/Implab/Implab.csproj Tue Apr 04 12:04:05 2017 +0300 @@ -81,9 +81,11 @@ + +