views:

3033

answers:

5

In ASP.NET, I usually log exceptions server-side, I win 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.

+3  A: 

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.

Srdjan Jovcic
+2  A: 

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!

TJB
+1  A: 

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.

tucod
A: 

It very much depends on the type of application that youre developing.

if its an mvc / mvp based architecture then your model, or most of it at least, will be on the server, and this is where most of your exceptions will be thrown i would imagine, so you can log them there and choose to display a message to the user or not.

for exceptions from the client you may want to know the details so just send them back.

A: 

For exceptions on the client side, I would try SMartAssembly. Much better than having your user copy paste a stack trace into an email.

http://www.smartassembly.com

Alex Davies