Tracing in MVC

Dheeraj Kumar Gunti

Reading Time : ( words)

Tracing the execution flow is very important in resolving lot of issues when working with a huge functionlity. This helps in identifying the statements executing and the fixing issues occured in the execution flow.

System.Diagnostics.Trace will help in acheiving this process.

Here is the small sample how we can acheive the tracing in an application. This is a basic sample, we can extend this to our needs.

public static class Tracer
    {
    public static void MyTrace(TraceLevel level, string message)
    {
    switch (level)
    {
    case TraceLevel.Error:
                               Trace.TraceError(message);
    break;
    case TraceLevel.Warning:
                               Trace.TraceWarning(message);
    break;
    case TraceLevel.Info:
                               Trace.TraceInformation(message);
    break;
    case TraceLevel.Verbose:
                               Trace.WriteLine(message);
    break;
    }
    }
}







Tracer.MyTrace(TraceLevel.Warning, "Warning Tracer");