.NET Framework provides a wide variety of tools and utilities. We can use StackTrace information to create a log which will help in logging the flow of execution along with useful information like method name, line number , module name etc.
BEGIN CODE******************
System.Diagnostics.StackFrame frame = new System.Diagnostics.StackFrame(1, true);
// 1 = it will skip the first frame . first frame is the curent frame. true will give the file name
System.Reflection.MethodBase method = frame.GetMethod();
string strLog = method.Name + ":" + method.DeclaringType.FullName + ":" + frame.GetFileLineNumber();
//You can retrieve parameters info also frame.GetMethod().GetParameters();
END CODE********************
Use this information at all the critical place in your code and you will have a very informative log file.
-Abhinaw
No comments:
Post a Comment