Friday, November 14, 2014

Debugging production issues

Some times we get weird issues in production and some of they are not consistent and canot be reproduced in development environment.To deal with such issues I am giving some tips based on my experience.

1)Fist thing we need to do is to check the application log files and database log tables and see if the information logged will help us in anyway to understand the root cause.If the information is not sufficient we can add extra logging and deploy the latest code to capture more information.

In below method we are capturing empId for additional information regarding the exceptional scenario.There are cases issues can be occurred for only particular employee so empId will help us in understanding the all employee information.

public List<Employee> GetEmployee(string empId)
{
............
}
catch (Exception exception)
{
var exMessage = exception.Message + Environment.NewLine +
exception.StackTrace + Environment.NewLine + "EmplId:" + empId;

Logger.Write(ErrorLogTittle, exMessage);
}

In GetEmployee method if there is any exception occurred it will log exception message,StackTrace and also empId.
StackTrace will help us in identifying the code file and line no apart from exception details.
Logging transaction details like empId is very important to find the root cause in some weird cases.
Catching the exceptions and logging the details in database table and also a text file before displaying the error to user should be compulsory.

In some scenarios,we might need to add additional logs to track the work flow.
a)Record processing started
b)Reading employee details
C).....
d)End
This way we can easily identify after which step the exception occurred.

2)In some scenarios like below
a)If our application is trying to access remote machines/Network resources.
b)Need some dll's for application functioning but unable to load.

We can get helpful information to identify the root cause from Windows event logs.

To check event logs,Open Run dialog box type and type eventvwr. Expand Windows Logs and click on Application. It will display the list of all application events.It will display 3 types of information.They are Information,Warning and Error.We know where to check right?


I will try to add more tips later.. :-)