Auto status change to "Under Review"
@@ -0,0 +1,74 | |||||
|
1 | using System; | |||
|
2 | using System.Collections.Generic; | |||
|
3 | using System.Diagnostics; | |||
|
4 | using System.Linq; | |||
|
5 | using System.Text; | |||
|
6 | using System.Threading.Tasks; | |||
|
7 | ||||
|
8 | namespace Implab.Diagnostics { | |||
|
9 | public static class Trace<T> { | |||
|
10 | ||||
|
11 | readonly static LogChannel<TraceEvent> _channel = new LogChannel<TraceEvent>(typeof(T).Name); | |||
|
12 | ||||
|
13 | public static LogChannel<TraceEvent> Channel { | |||
|
14 | get { return _channel; } | |||
|
15 | } | |||
|
16 | ||||
|
17 | /// <summary> | |||
|
18 | /// Starts the logical operation nested to the current operation nested to the current one. | |||
|
19 | /// </summary> | |||
|
20 | [Conditional("TRACE")] | |||
|
21 | public static void StartLogicalOperation() { | |||
|
22 | TraceContext.Instance.StartLogicalOperation(); | |||
|
23 | ||||
|
24 | } | |||
|
25 | ||||
|
26 | /// <summary> | |||
|
27 | /// Starts the logical operation with the specified name, this name is usefull in logs. | |||
|
28 | /// </summary> | |||
|
29 | /// <param name="name">Name.</param> | |||
|
30 | [Conditional("TRACE")] | |||
|
31 | public static void StartLogicalOperation(string name) { | |||
|
32 | TraceContext.Instance.StartLogicalOperation(name); | |||
|
33 | } | |||
|
34 | ||||
|
35 | /// <summary> | |||
|
36 | /// Ends the logical operation and restores the previous one. | |||
|
37 | /// </summary> | |||
|
38 | [Conditional("TRACE")] | |||
|
39 | public static void EndLogicalOperation() { | |||
|
40 | var op = TraceContext.Instance.EndLogicalOperation(); | |||
|
41 | LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(op, TraceEventType.OperationCompleted, String.Format("-{0} : {1}ms", op.Name, op.Duration))); | |||
|
42 | } | |||
|
43 | ||||
|
44 | /// <summary> | |||
|
45 | /// Writes an informational message. | |||
|
46 | /// </summary> | |||
|
47 | /// <param name="format">Format.</param> | |||
|
48 | /// <param name="arguments">Arguments.</param> | |||
|
49 | [Conditional("TRACE")] | |||
|
50 | public static void Log(string format, params object[] arguments) { | |||
|
51 | Channel.LogEvent(TraceEvent.Create(TraceContext.Instance.CurrentOperation, TraceEventType.Information, format, arguments)); | |||
|
52 | } | |||
|
53 | ||||
|
54 | /// <summary> | |||
|
55 | /// Writes a warning message. | |||
|
56 | /// </summary> | |||
|
57 | /// <param name="format">Format.</param> | |||
|
58 | /// <param name="arguments">Arguments.</param> | |||
|
59 | [Conditional("TRACE")] | |||
|
60 | public static void Warn(string format, params object[] arguments) { | |||
|
61 | Channel.LogEvent(TraceEvent.Create(TraceContext.Instance.CurrentOperation, TraceEventType.Warning, format, arguments)); | |||
|
62 | } | |||
|
63 | ||||
|
64 | [Conditional("TRACE")] | |||
|
65 | public static void Error(string format, params object[] arguments) { | |||
|
66 | Channel.LogEvent(TraceEvent.Create(TraceContext.Instance.CurrentOperation, TraceEventType.Error, format, arguments)); | |||
|
67 | } | |||
|
68 | ||||
|
69 | [Conditional("TRACE")] | |||
|
70 | public static void Error(Exception err) { | |||
|
71 | Error("{0}", err); | |||
|
72 | } | |||
|
73 | } | |||
|
74 | } |
@@ -0,0 +1,10 | |||||
|
1 | using System; | |||
|
2 | ||||
|
3 | namespace Implab.Diagnostics { | |||
|
4 | /// <summary> | |||
|
5 | /// Used to mark class which uses <see cref="Trace{T}"/> class to trace it's events | |||
|
6 | /// </summary> | |||
|
7 | [AttributeUsage(AttributeTargets.Class)] | |||
|
8 | public class TraceSourceAttribute : Attribute { | |||
|
9 | } | |||
|
10 | } |
@@ -81,9 +81,11 | |||||
81 | <Compile Include="Diagnostics\LogChannel.cs" /> |
|
81 | <Compile Include="Diagnostics\LogChannel.cs" /> | |
82 | <Compile Include="Diagnostics\LogicalOperation.cs" /> |
|
82 | <Compile Include="Diagnostics\LogicalOperation.cs" /> | |
83 | <Compile Include="Diagnostics\TextFileListener.cs" /> |
|
83 | <Compile Include="Diagnostics\TextFileListener.cs" /> | |
|
84 | <Compile Include="Diagnostics\Trace.cs" /> | |||
84 | <Compile Include="Diagnostics\TraceLog.cs" /> |
|
85 | <Compile Include="Diagnostics\TraceLog.cs" /> | |
85 | <Compile Include="Diagnostics\TraceEvent.cs" /> |
|
86 | <Compile Include="Diagnostics\TraceEvent.cs" /> | |
86 | <Compile Include="Diagnostics\TraceEventType.cs" /> |
|
87 | <Compile Include="Diagnostics\TraceEventType.cs" /> | |
|
88 | <Compile Include="Diagnostics\TraceSourceAttribute.cs" /> | |||
87 | <Compile Include="ICancellable.cs" /> |
|
89 | <Compile Include="ICancellable.cs" /> | |
88 | <Compile Include="IProgressHandler.cs" /> |
|
90 | <Compile Include="IProgressHandler.cs" /> | |
89 | <Compile Include="IProgressNotifier.cs" /> |
|
91 | <Compile Include="IProgressNotifier.cs" /> |
General Comments 3
ok, latest stable version should be in default
You need to be logged in to leave comments.
Login now