Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best practice for exception handling in silverlight?

In ASP.NET, I usually log exceptions at server-side, In windows forms I can either log exceptions server-side or write to a log file on the client. Silverlight seems to fit somewhere in between.

I wanted to know what everyone else is doing to handle their Silverlight exceptions and I was curious if any best practices have emerged for this yet.

like image 755
Jacob Adams Avatar asked Feb 23 '09 19:02

Jacob Adams


4 Answers

For real logging that you could store & track, you will need to do it on the server, since you can't be guaranteed anything on the client will be persisted.

I would suggest exposing a "LogEvent(..)" method on a server side web service (maybe you already have one) which would then do the same kind of logging you do in ASP.net

Here's a video about basic web service calls in Silverlight if you haven't done that yet http://silverlight.net/learn/learnvideo.aspx?video=66723

I'm not sure about any logging best practices though, my first guess would be to do the best practicies for logging in a web sevice on the server and expose that to the client.

Hope this helps!

like image 96
TJB Avatar answered Oct 27 '22 01:10

TJB


I would say that Silverlight fits much better to ASP.NET side of the model. You have server which serves web page. An object (Silverlight app) on the page pings data service to fetch data and display it.

All data access happens on the server side and it does not matter if data is used to create ASP.NET pages on the server or sent raw to the RIA for display. I do log any failures in data service on server side (event log works fine) and do not allow any exception to pass to WCF. When client does not receive expected data (it gets null collection or something similar), it display generic data access error to the user. We may need to extend that soon to pass a bit more information (distinguishing between access denied/missing database/infrastructure failure/internal error/etc), but we do not plan to pass exception error messages to the client.

As for client side, sometimes we may get in situation where async call times out -- it is just another message. For general exceptions from client code (typically, bugs in our code), I just pass exception to the browser to display in same manner as any script exception.

like image 26
Srdjan Jovcic Avatar answered Oct 26 '22 23:10

Srdjan Jovcic


Also take a look at the new Silverlight Integration Pack for Enterprise Library from Microsoft patterns & practices. It provides support for logging exceptions to isolated storage or remote services and is configurable via policies in external config or programmatically. Batch logging and automatic retry (in case of occasionally connected scenarios) are also supported.

like image 21
Grigori Melnik Avatar answered Oct 27 '22 00:10

Grigori Melnik


Use the Isolated Storage available for Silverlight application. You should store here your log.

Then you can develop a mecanism to send the user log to a webservice like the Windows bug report service.

like image 42
G. Ghez Avatar answered Oct 26 '22 23:10

G. Ghez