|
using System;
using System.Diagnostics;
using System.Reflection;
/// <summary>
/// Summary description for TraceWriter.
/// </summary>
internal sealed class TraceWriter
{
public static TraceSwitch Switch = new TraceSwitch(Assembly.GetAssembly(typeof(TraceWriter)).GetName().Name, "Trace Helper Switch");
public static void TraceError(string format, params object[] args)
{
if (Switch.TraceError)
Trace.WriteLine(string.Format(format, args), GetCallingMethod(new StackTrace(1)));
}
public static void TraceError(string value)
{
if (Switch.TraceError)
Trace.WriteLine(value, GetCallingMethod(new StackTrace(1)));
}
public static void TraceInfo(string format, params object[] args)
{
if (Switch.TraceInfo)
Trace.WriteLine(string.Format(format, args), GetCallingMethod(new StackTrace(1)));
}
public static void TraceInfo(string value)
{
if (Switch.TraceInfo)
Trace.WriteLine(value, GetCallingMethod(new StackTrace(1)));
}
public static void TraceWarning(string format, params object[] args)
{
if (Switch.TraceWarning)
Trace.WriteLine(string.Format(format, args), GetCallingMethod(new StackTrace(1)));
}
public static void TraceWarning(string value)
{
if (Switch.TraceWarning)
Trace.WriteLine(value, GetCallingMethod(new StackTrace(1))); }
public static void TraceVerbose(string format, params object[] args)
{
if (Switch.TraceVerbose)
Trace.WriteLine(string.Format(format, args), GetCallingMethod(new StackTrace(1)));
}
public static void TraceVerbose(string value)
{
if (Switch.TraceVerbose)
Trace.WriteLine(value, GetCallingMethod(new StackTrace(1)));
}
private static string GetCallingMethod(StackTrace stack)
{
StackFrame frame = stack.GetFrame(0);
string className = frame.GetMethod().DeclaringType.ToString();
string functionName = frame.GetMethod().Name;
return string.Format("{0}.{1}", className, functionName);
}
private TraceWriter()
{
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.