Click here to Skip to main content
15,884,628 members
Articles / Web Development
Tip/Trick

Error Reporting / Notification Service

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
26 Nov 2013CPOL1 min read 10.9K   121   9   2
Error notification service which helps make application more error free

Image 1

Introduction

This tip/code will be helpful to a developer after an application has been launched or configured on a client's server. After a website is live or launched, users will access the website. If a user faces an unexpected error, then no one gets to know what error it was. Developer or website admin will never get to know about such errors on live websites. So I coded for that to enable the website admin or developer to know about errors.

Using the Code

In this sample web application, three classes are available:

  • ErrorReporting
  • Email
  • Config

ErrorReporting.cs

We have a function SendApplicationError which accepts five parameters which are optional:

  • vstrErrorMessage (to set custom error message)
  • vstrErrorCode (to set custom error code)
  • vstrErrorType (to set custom error type)
  • vstrStackTrace (to set custom error stack trace)
  • vstrRedirectURL (out parameter to set auto redirection if any specific error found)
The above function will list all our server variables, cookies, posted values, referral URL, query string values, session values, etc..
C#
Config oConfig = new Config();
string strApplicationName = oConfig.getApplicationName();
string ToAddress = oConfig.GetString(String.Format("SMTP.Error.EamilTo"));
string FromAddress = oConfig.GetString(String.Format("SMTP.Error.EamilFrom"));
string strBCC = oConfig.GetString(String.Format("SMTP.DefaultBCCEmail"));

if (oConfig.isErrorEnable() == false)
{
    vstrRedirectURL = "";
    return;
}

Above values will be fetched from web.config using the customized config class.

Email.cs

Using this class, the system will automatically send an email to the respective website admin or mentioned email address and also set default BCC email if provided in web.config.

Config.cs

This customized class is used to fetch information or key values from web.config. Using this class, we also can set datatype, i.e., string, int, etc..

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
India India
I am now acquainted with computers for about 9 years. Having such an exposure makes it easier for me to adjust into environment of multinational companies using these languages. I have accomplished many projects while working in a group and thus I am able to communicate and coordinate with different members of the group very well.

  • An accomplished information technology professional with excellence in software development leadership and execution, including the use of Object Oriented Design (including design and enterprise patterns), UML, Service Oriented Architecture.
  • Extensive experience in Microsoft development technologies including; .Net (1.x, 2.0, 3.0, and 3.5). Visual Studio.Net , Visual Studio 2005 and 2008, Visual Basic.Net, C#, LINQ, ASP.Net, AJAX, ADO.Net Entity Framework, COM+, Web Services, XAML, XML and Azure.
  • Proven database expertise in; T-SQL, SQL Server, MSDE, SQL Server Express, SQL Compact Edition, DTS, Integration Services, Stored Procedures and Functions, MS Access, DB2, ADO, ADO.Net ODBC, DAO and Pervasive SQL.
  • Possess expertise in Object Oriented Analysis and Design as demonstrated in the use of Client Server, COM, COM+, Web Services.
  • Deep understanding of technology with a focus on delivering solutions that provide business value.



Programming:.NET, Entity Framework, LightSwitch, Object Oriented Analysis and Design, UML, Client Server, COM, COM+, Web Services
Languages: VB.NET, C#, PHP, XAML, VB, XML, ASP.NET, ASP, VBScript, VBA, HTML, FTP, Java, JavaScript
Databases: SQL, T-SQL, DTS, SQL Server 7/2000/2005, MySQL, Stored Procedures, MSDE, MS Access , ADO.NET, ADO, ODBC, DAO, Pervasive SQL
Operating Systems: Windows 9x/NT/2000/XP/Vista/7, Windows Server, DOS

Comments and Discussions

 
Questionwhat is the use of arraylist ErrMsg Pin
Mukund Thakker28-Nov-13 22:58
professionalMukund Thakker28-Nov-13 22:58 
AnswerRe: what is the use of arraylist ErrMsg Pin
Dusara Maulik5-Dec-13 21:59
Dusara Maulik5-Dec-13 21:59 
1) You can remove this arraylist. This will not use anywhere. I used this this code for some customization.
2) This Error Notification server will automatically called when Application_Error event will be triggerd. But in special case if we want to notify admin user regarding an error like some data wrong or if any developer is using try catch block. You can use below statement to call this function.

C#
string lstrRedirectURL = string.Empty;
ErrorReporting.SendApplicaitonError("CustomErrorMessage", "CustomErrorCode", "CustomErrorType", "CustomStackTrace", out lstrRedirectURL);
if (lstrRedirectURL != "")
{
    Response.Redirect(lstrRedirectURL);
}

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.