Thursday, April 30, 2009

Getting MethodName,LineNumber and Module Name for logging

.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

Wednesday, April 29, 2009

Function Name and Line Number in Visual Studio 2008

It is very helpful to log the function name and also the line number in a log file. Investigating the root cause of an exception or error requires knowing the problem area first. Function name and line number are narrow down the problem to a specific area which can save time and effort.

Here is the simple and convenient way to log the function name.

Environment.StackTrace.Split(Environment.NewLine.ToCharArray()))[4]

-Abhinaw

Monday, April 27, 2009

Restore Bookmarks in Firefox (Mozilla)

To restore bookmarks in firefox. Follow these easy steps:
1) Go to C:\Documents and Settings\yourusername\Application Data\Mozilla\Firefox\Profiles
2) you will find a folder with a name like zzzzz .default. Open this folder by double clicking it.
3) places.sqlite - Copy this file from the default folder which you opened in step 2.
4) Now go to the C:\Documents and Settings\new username\Application Data\Mozilla\Firefox\Profiles folder
5) Open a folder named something like as zzzzzz.default.
6) paste the palces.sqlite file which you copied in step 3.

You are done. You will see all your bookmarks which you saved in your previous profile will appear in your new profile.

-Abinaw