using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
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() {
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 TraceInformation(string format, params object[] arguments) {
LogChannel.Default.LogEvent(TraceEvent.Create(TraceContext.Instance.CurrentOperation, 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(TraceContext.Instance.CurrentOperation, TraceEventType.Warning, format, arguments));
}
[Conditional("TRACE")]
public static void TraceError(string format, params object[] arguments) {
LogChannel.Default.LogEvent(TraceEvent.Create(TraceContext.Instance.CurrentOperation, TraceEventType.Error, format, arguments));
}
[Conditional("TRACE")]
public static void TraceError(Exception err) {
TraceError("{0}", err);
}
}
}