Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Error Reporting / Notification Service

0.00/5 (No votes)
26 Nov 2013 1  
Error notification service which helps make application more error free

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..
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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here