Customizing exception error messages

By Fernando Sousa on 11 May 2010
We often use an extension to write logs to the Error Log table of Service Center (similar to the tip given at in order to write more information that could help to understand the reason that lead to the problem, like the username that was executing an action, value of important variables, etc.
We use this method because usually audits are disabled in production environments and are often used for debug logs, so trying to understand what happened when you have many users accessing your application could be a hard task. Also, with an error log you can write a lot more information than with an audit log (e.g.: you can output an entire XML that you were parsing instead of having only the first 200 characters).

When an exception is raised, you can choose to log the exception message and stack or not, but you cannot send additional information to that error log.
Although you can access the exception message with Session.ExceptionMessage, there is no way to get the stack. So, in order to get the best out of it, we end up logging two events for the same error: one by the error handler and another customized with some additional information.

My suggestion is to either create something like Session.ExceptionStack or allowing the user to log custom data in the Error Handler.
I think this is gonne be very handy.

In the application I'm now working we created our own table to log all errors, so we can see who did it and what happend. It would be handy to have the most of these seen in service center.

Only you do need to think about the amount of messages that can be very much (lets go for a worst case ;)) and you can't find the messages you want to see.