Friday, August 21, 2009

Tip To Log

We often like to know what happens in a procedure and also we like to figure out if we see something in the log, where in the code it happened. Therefore it is handy to start and end each procedure with log. To do this we can put a small generic code like this


Trace.WriteLine("Beginning with " + System.Reflection.MethodInfo.GetCurrentMethod().Name);

it will work just fine

1 comment:

Pouya Panahy said...

///
/// Logs the calling method when Verbose mode
///
public static void Starting()
{
if (!GeneralSwitch.TraceVerbose) return;
var method = new System.Diagnostics.StackFrame(1).GetMethod();

System.Diagnostics.Trace.WriteLine(string.Format(formatSTARTING,
method.ReflectedType.FullName,
method.Name, "-"), "STARTING");
}