Exception Helper
Introduction
ExceptionHelper is the open source .NET project coded with C#. It helps developers implement exception management into ASP.NET Web Application. The main purposes of ExceptionHelper is to give detailed exception information to developers.
You can download ExceptionHelper project and demo web application in order to understand how ExceptionHelper works.
When you open the SlnExceptionHelper, you will see default.aspx web page I created in order to show how ExceptionHelper can be used. In this code-behing there is a try-catch block where I intentionally thrown an exception. In catch block, I invoked HandleException which is overloading method by passing some parameters.
I want you to focus BasePage.cs which is placed in DemoWeb project to see how you can implement ExceptionHelper into your current or upcoming project. In BasePage.cs, please look at HandleException overloading methods where you can comprehend usage of ExceptionHelper.
Capabilities of ExceptionHelper
ExceptionHelper supports following functionalities:
- You can have xml-based detailed exception content with current user information logged in to system and extra information you want to add into exception content.
- You can save xml-based detailed exception content into a file.
- You can insert xml-based detailed exception content to your database.
- You can send xml-based detailed exception content as an email to your team members who responsible for the application.
How to Generate xml-based Exception Content?
In order to generate exception content, first of all, you need to create instance of ExceptionInfo which has three overloading constructors.
In first code sample below, first create instance of ExceptionInfo without sending any parameters to its constructor then call GenerateMethod with exception parameter which is thrown.
XDocument exceptionContent = oException.GenerateContent(<ExceptionObject>);
In second code sample below, first create instance of ExceptionInfo with parameter which is CurrentUserInformation,which contains web user data which logged in to system, whose type is NameValueCollection. then call GenerateMethod with exception parameter which is thrown.
XDocument exceptionContent = oException.GenerateContent(ex);
In second code sample below, first create instance of ExceptionInfo with parameters which are CurrentUserInformation,which contains web user data which logged in to system, whose type is NameValueCollection and AdditionalInformation,which consists of extra information about exception that is needed , whose type is Generic List Collection which accepts only string type. then call GenerateMethod with exception parameter which is thrown.
How to Save Exception Content into a File?
After generating xml-based exception content, you can save it into a file.
PublishManager is an abstract class consisting Publish method. FilePublishManager is the class inherited by PublishManager. As you see, you need to pass folder path where you want to save the exception content.
How to Insert Exception Content into Database?
After generating xml-based exception content, you can insert it into your database.
PublishManager is an abstract class consisting Publish method. DBPublishManager is the class inherited by PublishManager.
How to Send Exception Content as an Email to People who Responsible for?
After generating xml-based exception content, you can send it to your team members who responsible for the software application.
PublishManager is an abstract class consisting Publish method. EmailPublishManager is the class inherited by PublishManager. As you see, you need to pass EmailInfo object parameter used to send the exception content.
EmailInfo is the class which contains of following attributes :
- To is the generic list collection which accepts only EmailAddress object.To attribute determines the emails where exception content is sent.
- From is the EmailAddress object.From attribute is used to define email address from where email is sent.
- Subject is the title of email.
- Body is the attribute where you can set exception content to.
- Server shows ip address of the server where email is sent.
EmailAddress is the class consisting of Address, which represents email address, and DisplayName which is the name shows who sends the email.



