views:

52

answers:

2

Lately our customers are experiencing unexpected crashes. We are already logging the errors on their local machines. Is there a mechanism to enable them to "send error log" somehow when the application crashes or when unexpected behavior takes place?

In other word how do I know that the application freezed or hung or crashed so I can send something, and override the normal "not responding" windows message?

+2  A: 

I don't think there's much you can do if it's hung but if it crashes you might be able to catch some of those crashes with the UnhandledExceptionEventHandler.

You could possibly handle the hangs by checking when the application starts up if it previously shut down correctly and wrote a "shutting down" message to the log, and if it didn't you could ask the user if they want to send the log to you.

ho1
+1: Agreed, log the user activity as well as exceptions - check upon restart.
KMan
A: 

In the past I've had luck with logging exceptions to a webservice (as long as the client are allowed to log out to the internet) with code like the one below. This is for logging anything you're not already catching. If you compile your application in release mode but also include the pdb files, you will get a stacktrace with line numbers.

You should also log the version of your assembly to know what version of the application is giving you errors.

public void RegisterHandlers()
{
    Application.ThreadException += new ThreadExceptionEventHandler(ThreadExceptionFunction);
    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionFunction);
}

private void UnhandledExceptionFunction(object sender, UnhandledExceptionEventArgs args)
{
    Exception e = (Exception)args.ExceptionObject;
    ExceptionLogger(e.StackTrace);
}

private void ThreadExceptionFunction(object sender, ThreadExceptionEventArgs args)
{
    ExceptionLogger(args.Exception.StackTrace);
}

private void ExceptionLogger(string trace)
{
    // log the message to a webservice
}
Mikael Svenson