Anyone built a system to be notified of errors as they occur on your store? I've seen this with other carts and I'm getting ready to implement a system now as I'm seeing a lot of errors in the App_Data/log file that are not being reported in the Help/Error log area. So if anyone has something built and cares to share, please post or redirect me to it.
Thx
Notification of ERRORS
- NC Software
- AbleCommerce Partner
- Posts: 4620
- Joined: Mon Sep 13, 2004 6:06 pm
- Contact:
Notification of ERRORS
Neal Culiner
NC Software, Inc.
NC Software, Inc.
Re: Notification of ERRORS
The best possiable solution I could think of for error alert will be someting like below
1)- Create a new Email Template for example name it Error Notification, then adjust its layout and put some expected NVelocity vairable to show respective data.
2)- Now in Global.asax file put some code in Application_Error event to load and trigger newly added Email template with appropriate data.
Here are the basic changes needed for this modification. You can enhance the posted Email template to accommodate your custom needs. So download, extract and place the Error Notification.html file in App_Data/Email Templates/1 folder. Next job is to create a new Email Template and assign it the newly added email template file. In to address section put the Email address where you want to receive error alert. Then put following text in the subject text box
and don't forget to mark Send as HTML checkbox.
Then note the EmailTemplateId of this newly added Email template from the query and go to Global.asax and edit file, and change its Application_Error error method as below
Where email template code under Logger.Error statement is newly added code. Now replace emailTempalteId with actual integer value of your error notification Email template id. That's it now you will receive error notification when some problem occurs at your store.
1)- Create a new Email Template for example name it Error Notification, then adjust its layout and put some expected NVelocity vairable to show respective data.
2)- Now in Global.asax file put some code in Application_Error event to load and trigger newly added Email template with appropriate data.
Here are the basic changes needed for this modification. You can enhance the posted Email template to accommodate your custom needs. So download, extract and place the Error Notification.html file in App_Data/Email Templates/1 folder. Next job is to create a new Email Template and assign it the newly added email template file. In to address section put the Email address where you want to receive error alert. Then put following text in the subject text box
Code: Select all
Error occured at $store.Name
Then note the EmailTemplateId of this newly added Email template from the query and go to Global.asax and edit file, and change its Application_Error error method as below
Code: Select all
protected void Application_Error(Object sender, EventArgs e)
{
// ENABLE ERROR LOGGING FOR SCRIPTS OUTSIDE OF THE INSTALL DIRECTORY
if (!HttpContextHelper.IsInstallRequest())
{
// RECORD THE DETAILS TO THE AC ERROR LOG
HttpContext ctx = HttpContext.Current;
Exception exception = ctx.Server.GetLastError();
// IGNORE INVALID VEIW STATE ERRORS
if (IsViewStateException(exception)) return;
string errorInfo = "An error has occured at " + ctx.Request.Url.ToString();
Logger.Error(errorInfo, exception);
EmailTemplate emailTemplate = EmailTemplateDataSource.Load(emailTempalteId);
if (emailTemplate == null)
return;
emailTemplate.Parameters.Add("store", Token.Instance.Store);
emailTemplate.Parameters.Add("exception", exception);
emailTemplate.Send();
}
}
- NC Software
- AbleCommerce Partner
- Posts: 4620
- Joined: Mon Sep 13, 2004 6:06 pm
- Contact:
Re: Notification of ERRORS
Thanks for the info, rapid reply, and helpful information that will benefit others. It's also a nice tutorial on the messaging system. I changed the code slightly for anyone else that wants this. I haven't received any e-mails yet to verify so we'll tweak as time goes on. I added a $message to my e-mail template to write the information in as you'll see the code change below:
Code: Select all
protected void Application_Error(Object sender, EventArgs e)
{
// ENABLE ERROR LOGGING FOR SCRIPTS OUTSIDE OF THE INSTALL DIRECTORY
if (!HttpContextHelper.IsInstallRequest())
{
// RECORD THE DETAILS TO THE AC ERROR LOG
HttpContext ctx = HttpContext.Current;
Exception exception = ctx.Server.GetLastError();
// IGNORE HttpExceptions
//if (exception is HttpException) return;
// IGNORE INVALID VIEW STATE ERRORS
if (IsViewStateException(exception)) return;
//string errorInfo = "An error has occured at " + ctx.Request.Url.ToString();
//Logger.Error(errorInfo, exception);
EmailTemplate emailTemplate = EmailTemplateDataSource.Load(17);
if (emailTemplate == null)
return;
string errorInfo =
"<br>Offending URL: " + ctx.Request.Url.ToString() +
"<br>Source: " + exception.Source +
"<br>Message: " + exception.Message +
"<br>Stack trace: " + exception.StackTrace;
Logger.Error(errorInfo, exception);
emailTemplate.Parameters.Add("store", Token.Instance.Store);
emailTemplate.Parameters.Add("exception", exception);
emailTemplate.Parameters.Add("message", errorInfo);
emailTemplate.Send();
}
}
Neal Culiner
NC Software, Inc.
NC Software, Inc.
- RichWendrock
- Commander (CMDR)
- Posts: 134
- Joined: Sat Apr 05, 2008 12:55 am
- Location: Austin Texas
- Contact:
Re: Notification of ERRORS
Since this post is two years old and I see another method for emailing errors using log4net. Which option is best?
I implemented log4net and it does send an email for each event. Occasionally, we get a url coming in that is invalid. In place of &CategoryId= we get &CategoryId=. I would like to know the origin of the requests. I came to the forum looking for a way to capture the REFERRER URL. Still looking. Does anyone know?
I implemented log4net and it does send an email for each event. Occasionally, we get a url coming in that is invalid. In place of &CategoryId= we get &CategoryId=. I would like to know the origin of the requests. I came to the forum looking for a way to capture the REFERRER URL. Still looking. Does anyone know?
Regards,
Richard
http://www.TheHomePageStore.com
AbleCommerce
VERSION: 7.0.7.14588
MSSQL v2005
AC SCHEMA v2005
.NET CLR v2.0.50727.3634
Richard
http://www.TheHomePageStore.com
AbleCommerce
VERSION: 7.0.7.14588
MSSQL v2005
AC SCHEMA v2005
.NET CLR v2.0.50727.3634
Re: Notification of ERRORS
We use ELMAH for our clients hosted with us and it works great. You can set up email notifications, web page or RSS error feed.
http://code.google.com/p/elmah/
The ELMAH install requires only elmah.dll copy in your Ablecommerce /bin folder and few lines of web.config code. You can switch on/off error
handling directly from the web.config file. No AbleCommerce code or other changes required.
http://code.google.com/p/elmah/
The ELMAH install requires only elmah.dll copy in your Ablecommerce /bin folder and few lines of web.config code. You can switch on/off error
handling directly from the web.config file. No AbleCommerce code or other changes required.
Mike Kolev