18 Kasım 2011 Cuma

Receive errors that occur in your site with SMS

Previously we could learn from log file.Do you know, You can receive errors on your site as sms?



Note : I wrote this aricle in 2010. I decided publish  this article as English. I hope, this article will be helpful..


Introduction


Previously we could learn from log file.Do you know, You can receive errors on your site as sms?

Background

What should for this?
1) A google account for access to Google Calendar. İf you have a gmail account;you wont need another account, because google use common account for its services.
2) You should download Google API for linking your application with Google Services. You can download from this link (Note:This application created using NET framework and C#. So you should download .NET packages.)
3)Update your profile entering your mobile number. You will receive verification code. You should enter it to your profile panel.
4) Create an application file (Global.ASAX) for your application

Using the code

Google remind entered activity at time you wish.
You can define it as hour,minute or second. This reminder will reach by choosed method.(You can choose Email or SMS.)
SMS option is basic of our application. We will enter an activity Google Calendar when error occured. Time of activity should be three minutes later then error's time. Also, You will set as SMS reminder. This is logic of our application.
As known as, Global.ASAX contains application and session events.These events will be triggered when application and session starts and ends.
We are creating Global.ASAX file on our application. After this, We are including API file as reference in our application.
After including, We are adding following namespaces in our code:

< % @ Import Namespace="Google.GData.AccessControl" % >
< % @ Import Namespace="Google.GData.Calendar" % >
< % @ Import Namespace="Google.GData.Client" % >
< % @ Import Namespace="Google.GData.Extensions" % >

Update following code with your google account information and add under the Application_Eror event.
Exception hata = Server.GetLastError();
CalendarService myService = new CalendarService("uygulama1");
myService.setUserCredentials(account@gmail.com, "password");
Google.GData.Calendar.EventEntry entry = new Google.GData.Calendar.EventEntry
(Request.Path.ToString()+":"+hata.InnerException.Message, Request.Path.ToString()
+":"+hata.InnerException.Message, "web");


DateTime zaman = new DateTime(DateTime.Now.Year, DateTime.Now.Month,
DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.AddMinutes(2).Minute, 0);
When eventTime = new When(zaman, zaman.AddMinutes(3));
Reminder r = new Reminder();
r.Method = Reminder.ReminderMethod.sms;
r.Minutes = 1; entry.Times.Add(eventTime);
entry.Reminders.Add(r);
Uri postUri = new Uri("http://www.google.com/calendar/feeds/default/private/full");
myService.Insert(postUri, entry);
That's all.

Points of Interest

You can receive on your site errors as sms and free

History

Created 12 Feb 2010

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Hiç yorum yok: