Exception Error Handling Log Maintenance in a Text File: Part 2
In this article I will describe how to use the "ErrorHandling" dll when an exception happens and how to register the Exception in a text file.
In my previous article we got to know how to create two methods that handle the log maintenance for exceptions. After that just build the application and we will get the "dll" of the project. The link of my previous article is
Now in this article I will describe how to use the "ErrorHandling" dll when an exception happens and to register the Exception in a text file. The textfile will be created inside the "LogError" folder in the C drive. So before attaching the dll you have to create the folder in your C drive.
Now here is the Program.
First create a webapplication named "Errorhandlingappln".
After that in the reference folder add a reference for "Errorhandling.dll". In this project I will give you the dll.
After attaching the dll it will appear in your reference folder and it will appear like the following figure:
Now in the default.aspx.cs first register the dll.
Now see the following code:
public partial class _Default : System.Web.UI.Page
int i = 10,d=0;
ErrorHandling objError = new ErrorHandling();
protected void Page_Load(object sender, EventArgs e)
int result = (i /d) ;
catch (Exception ee)
string errorMessage = ErrorHandiling .Class1.CreateErrorMessage(ee);
Here I simply divide the integer i to 0. That means the ArithmaticException will occur.
So in the Catch block
First create the Exception error message with inner Exception by pasing the Exception object. ErrorHandling is our dll class name.
Secondly we are passing the "errorMessage" to the method name " LogFileWrite" to create the txtfile.
Now run the program. Obliviously the Exception will occur. Now go to the "LogError" folder and you will see the logtext file name "ProgramLog-20110711" just like the following figure.
Now open the text file; you will see exception details information that have been generated by our program exception like the following figure.
So in this article we have seen how to use the "ErrorHandling" dll when an exception happens and how to register the exception in a text file.