Jun 30, 2008

Send .Net Runtime Error messages with Email

I have returned from vacation today. I have many works to do. I see my coworkers are not happy. Emails tell me everything. Error messages, user requests, bad test results, meetings, works, works...

In one week there are 201 .net runtime error emails. There are some problems with some developments.

We configured .net settings to emails runtime errors to us with detailed information. It is useful sometimes. But be careful, if you face many runtime errors your mailbox may be full. I recommend you to redirect error emails to your secondary email address if you have mail quota problems. If you want to use with your primary address you should filter messages and move them to new folder. So tracking error messages would be more easy.

I want to mention about how can we send error messages as we use. Our code works with .Net 1.1 version and not tested with upper versions. I think it should work with new versions.

Go to global.asax.vb and find Application_Error function. You may see "Fires when an error occurs" comment in it. In this function open try/catch block and paste code below in it.

Dim ex As Exception = Server.GetLastError().GetBaseException()
Dim ErrorMessage As String = ""
ErrorMessage = "<b>Error date :</b>" & DateTime.Now
ErrorMessage &= "<br><b>Error message : </b>" & ex.Message
ErrorMessage &= "<br><b>Error page and location :</b>" & ex.StackTrace
ErrorMessage &= "<br><b>User : </b>" & Session("ID_USER") 'If you have user info

'Submitted Form Information
ErrorMessage &= "<br><p><b><u>Form Info</u></b>"
Dim x As Integer = 0
Do While x < Request.Form.Count
ErrorMessage &= "<LI>" & Request.Form.Keys(x) & " : " & Request.Form(x) & ""
x += 1
Loop

'Server Variables
ErrorMessage &= "<p><b><u>Server Variables</u></b>"
x = 0

Do While x < Request.ServerVariables.Count
ErrorMessage &= "<LI>" & Request.ServerVariables.Keys(x) & " : " & Request.ServerVariables(x) & ""
x += 1
Loop

Dim objMsg As New System.Web.Mail.MailMessage
objMsg.BodyFormat = Mail.MailFormat.Html
objMsg.From = ConfigurationSettings.AppSettings("From")
objMsg.Subject = "Test Error! "
objMsg.To = "mail@mail.com" 'Your email address
objMsg.Body = ErrorMessage
System.Web.Mail.SmtpMail.SmtpServer = ConfigurationSettings.AppSettings("Smtp")
System.Web.Mail.SmtpMail.Send(objMsg)

Notes:
  • We keep "From" and "Smtp" variables in webconfig file. You can change it as you wish.
  • We do not email errors on production environment. Just using for test purposes.

Jun 28, 2008

Power of UI

When i was writing my "Exploring Ajax" article i mentioned a little bit to user interface. But then i delete one paragraph to make article more consistent. I do not want to throw that paragraph to trash.
Here is cut statements:
We need to ajax. We need to prevent post backs. We need to simplify user interfaces. Users should use project willingly by ease of use. I know some user interface developments are more valuable than complex business processes. Users do not see back end of the program. They know what they see. I remember we did a complex algorithm for a program. It was very hard indeed. We worked many weeks. Unfortunately users were not satisfied.

One day i changed icons on the screen. The project was transferred to us from another development group and they had used some ugly icons on the toolbar and menus. When users saw new clear icons they thank to us and started to use program and gave their feedback. Indeed program was working. But they did not want to work on it before. So they did not make tests and they behave like program had problems. It was a good experience for me.

No need to argue on power of the UI :)
 Categories :

Jun 27, 2008

Exploring ajax

I am on vacation now. I have not coded anything since last friday. But i can not stay away from coding. From last friday to today every night exploring for ajax frameworks and components. I want to recommend ajaxian and ajaxrain websites. I found good articles and examples about ajax frameworks on these sites. Of course there are many ajax sites but i recommend you to add these to your feed reader.

Anyway, i tested many ajax components but i am confused now. I could not make a decision to use which. Script.aculo.us and moo tools are my favourites. Yahoo, adobe and google also have their frameworks. If you are interested with ajax you know there are hundreds of ajax components. So which is the best?

First i need to make a decision for what purpose i will use this components. Now i have not a new project to start. The project that i work is written with vb.Net 2003. Project owners did not prefer to use any javascript framework when they started the project. Now there are over 200 hundred pages in the project. Also the development of the project continues without a break and all developments are critical as users say. As you see it is not easy to change all logic and pass all pages to javascript framework.

First action plan may be changing .net version from 1.1 to 2.0. So we can use update panel to provide ajax support and prevent postbacks. The simplest solutions seems to be version upgrade.

If i start a new project i should use javascript framework and proper ajax components. What is your opinion? I should make my own ajax library. Then make a plan which features of ajax i will use. This topic is endless :) I dont want to add anything but i should write a new article about ajax.

"This is the first post. Sorry if i have any mistakes (knowledge or english). You can comment my posts and warn me if you see any mistake."
 Categories :