namespace Tools.DotNet
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
///
/// Implémentation d'un pour les traces dot net
///
internal class TraceSourceTracer : Tracer
{
///
/// The real tracer used to write logs
///
private TraceSource realTracer;
///
/// Initializes a new instance of the class.
///
/// Name of the trace.
public TraceSourceTracer(String traceName)
{
this.realTracer = new TraceSource(traceName);
}
///
/// Writes the error.
///
/// Name of the component.
/// Operation done.
/// The message.
public override void WriteError(string component, string methodProperty, string message)
{
this.realTracer.TraceEvent(TraceEventType.Critical, 0, String.Format("[{0}] {1}", methodProperty, message));
this.realTracer.Flush();
}
///
/// Writes the error.
///
/// Name of the component.
/// Operation done.
/// The exception.
public override void WriteError(string component, string methodProperty, Exception exception)
{
this.realTracer.TraceEvent(TraceEventType.Critical, 0, String.Format("[{0}] {1}", methodProperty, exception.GetTrace()));
this.realTracer.Flush();
}
///
/// Writes the error.
///
/// Name of the component.
/// Operation done.
/// The message.
/// The exception
public override void WriteError(string component, string methodProperty, string message, Exception exc)
{
this.realTracer.TraceEvent(TraceEventType.Critical, 0, String.Format("[{0}] {1} - {2}", methodProperty, message, exc.GetTrace()));
this.realTracer.Flush();
}
///
/// Writes the information.
///
/// Name of the component.
/// Operation done.
/// The message.
public override void WriteInformation(string component, string methodProperty, string message)
{
this.realTracer.TraceEvent(TraceEventType.Information, 0, String.Format("[{0}] {1}", methodProperty, message));
this.realTracer.Flush();
}
///
/// Writes the start operation.
///
/// Name of the component.
/// Operation done.
/// The message.
public override void WriteStartOperation(string component, string methodProperty, string message)
{
this.realTracer.TraceEvent(TraceEventType.Start, 0, String.Format("[{0}] {1}", methodProperty, message));
this.realTracer.Flush();
}
///
/// Writes the stop operation.
///
/// Name of the component.
/// Operation done.
/// The message.
public override void WriteStopOperation(string component, string methodProperty, string message)
{
this.realTracer.TraceEvent(TraceEventType.Stop, 0, String.Format("[{0}] {1}", methodProperty, message));
this.realTracer.Flush();
}
///
/// Writes the verbose.
///
/// Name of the component.
/// Operation done.
/// The message.
public override void WriteVerbose(string component, string methodProperty, string message)
{
this.realTracer.TraceEvent(TraceEventType.Verbose, 0, String.Format("[{0}] {1}", methodProperty, message));
this.realTracer.Flush();
}
///
/// Writes the warning.
///
/// Name of the component.
/// Operation done.
/// The message.
public override void WriteWarning(string component, string methodProperty, string message)
{
this.realTracer.TraceEvent(TraceEventType.Warning, 0, String.Format("[{0}] {1}", methodProperty, message));
this.realTracer.Flush();
}
}
}