TraceLog.cs
70 lines
| 2.7 KiB
| text/x-csharp
|
CSharpLexer
|
|
r36 | using System; | ||
| using System.Collections.Generic; | ||||
| using System.Diagnostics; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
| namespace Implab.Diagnostics { | ||||
| /// <summary> | ||||
|
|
r195 | /// This class is used to trace a logical flow of the application, it publishes events to the default <see cref="TraceEvent"/> channel. | ||
|
|
r36 | /// </summary> | ||
| public static class TraceLog { | ||||
|
|
r195 | /// <summary> | ||
| /// Starts the logical operation nested to the current operation nested to the current one. | ||||
| /// </summary> | ||||
|
|
r36 | [Conditional("TRACE")] | ||
| public static void StartLogicalOperation() { | ||||
|
|
r92 | TraceContext.Instance.StartLogicalOperation(); | ||
|
|
r195 | |||
|
|
r36 | } | ||
|
|
r195 | /// <summary> | ||
| /// Starts the logical operation with the specified name, this name is usefull in logs. | ||||
| /// </summary> | ||||
| /// <param name="name">Name.</param> | ||||
|
|
r36 | [Conditional("TRACE")] | ||
| public static void StartLogicalOperation(string name) { | ||||
|
|
r92 | TraceContext.Instance.StartLogicalOperation(name); | ||
|
|
r36 | } | ||
|
|
r195 | /// <summary> | ||
| /// Ends the logical operation and restores the previous one. | ||||
| /// </summary> | ||||
|
|
r36 | [Conditional("TRACE")] | ||
| public static void EndLogicalOperation() { | ||||
|
|
r195 | var op = TraceContext.Instance.EndLogicalOperation(); | ||
| LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(TraceEventType.OperationCompleted, String.Format("-{0} : {1}ms",op.Name, op.Duration))); | ||||
|
|
r52 | } | ||
|
|
r195 | /// <summary> | ||
| /// Writes an informational message. | ||||
| /// </summary> | ||||
| /// <param name="format">Format.</param> | ||||
| /// <param name="arguments">Arguments.</param> | ||||
|
|
r52 | [Conditional("TRACE")] | ||
|
|
r36 | public static void TraceInformation(string format, params object[] arguments) { | ||
| LogChannel<TraceEvent>.Default.LogEvent(TraceEvent.Create(TraceEventType.Information, format, arguments)); | ||||
| } | ||||
|
|
r195 | /// <summary> | ||
| /// Writes a warning message. | ||||
| /// </summary> | ||||
| /// <param name="format">Format.</param> | ||||
| /// <param name="arguments">Arguments.</param> | ||||
|
|
r36 | [Conditional("TRACE")] | ||
| public static void TraceWarning(string format, params object[] arguments) { | ||||
| LogChannel<TraceEvent>.Default.LogEvent(TraceEvent.Create(TraceEventType.Warning, format, arguments)); | ||||
| } | ||||
| [Conditional("TRACE")] | ||||
| public static void TraceError(string format, params object[] arguments) { | ||||
| LogChannel<TraceEvent>.Default.LogEvent(TraceEvent.Create(TraceEventType.Error, format, arguments)); | ||||
| } | ||||
| [Conditional("TRACE")] | ||||
| public static void TraceError(Exception err) { | ||||
| TraceError("{0}", err); | ||||
| } | ||||
| } | ||||
| } | ||||
