6

例外がアプリケーションの先頭まで伝播する場合(もちろん、これは決して発生しません)、プログラムがクラッシュする前にエラーレポートを送信するオプションを提供したいと思います。私が念頭に置いているのは、Main関数のすべてをtry-catchでラップし、スタックトレースやその他の情報をサーバーに送信する小さなクラスです。簡単そうに聞こえますが、このようなものでは、私が十分に考慮していないハードル(セキュリティ、将来性など)があると確信しています。

この目的のための既存の.NETライブラリ/プロジェクトはありますか?または、これは正しいアプローチのように聞こえますか?単にアプリケーションのエントリポイントですべての例外をキャッチしますか?

4

7 に答える 7

1

私の標準的な免責事項:私はこの製品の開発者です。

私が働いている会社(PreEmptive Soltutions)によって作成された製品(Runtime Intelligence)を使用すると、エラーレポートだけでなく、ユーザーがアプリケーションを使用している時期と、最小限のコーディングで使用している機能を追跡する機能も注入できます。

Dotfuscatorを使用してコードインジェクション(またはILウィービング)を実行し、アプリケーションバイナリに新しいコードを挿入して、使用状況データを施設でホストされているサーバー(またはオプションで他の任意のURL)に送り返します。あなたが私たちにデータを送るならば、私たちはあなたに多くの強力な分析ツールと使用法に関するレポートを提供します。

この機能の基本バージョンは、Visual Studio 2010に含まれ、無料のデータレポートポータルにアクセスできます(ただし、SLA、データ保持の保証、またはデータのプライバシーはありません)。

使用情報とともに任意のデータを送り返す機能は商用製品に限定されていますが、完全に機能する無料の時間制限付き評価バージョンについては、PreEmptiveSoltutionsにお問い合わせください。

以下のサンプルコードを使用して、エラー報告を実行できます。

public partial class app : Application {
// field to temporarily store exception data        
    private Exception exp;
    void AppStartup(object sender, StartupEventArgs args) {
        // add a handler to catch any unhandled exceptions    
        this.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(ErrorHandler); 
        Window1 mainWindow = new Window1();
        mainWindow.ShowDialog();
    }

    // this will prompt the user if they want to report the exception
    void ErrorHandler(object sender, DispatcherUnhandledExceptionEventArgs e) {
        this.exp = e.Exception;
        if (MessageBox.Show("A " + exp.Message + " exception happened, should I report it?", "Error Occurrend", MessageBoxButton.YesNo) == MessageBoxResult.Yes) {
            ErrorHappened();
            e.Handled = true;
        }
    }

    // this method is called by the above ErrorHandler method and when run through Dotfuscator additional code will be injected into this method that will send a usage data message back to the server and the data in the dictionary (which will be exception data) returned by the ErrorData method will be included into the message and be stored and reported on the server
    [Feature("Exception", EventType = FeatureEventTypes.Tick, ExtendedKeySourceElement = SourceElements.Method, ExtendedKeySourceName = "ErrorData")]
    private void ErrorHappened() {
        // This is here as a placeholder for the exception feature attribute which will exit the application when executed
        AppShutdown(true);
    }

    // this method takes the exception data from the exp field and returns it as a dictionary of name/value pairs
    public Dictionary<string, string> ErrorData() {
        var retval = new Dictionary<string,string>();
        if (null != exp) {
            retval.Add("Error Message",exp.Message);
            retval.Add("Stack Trace",exp.StackTrace);
        }
        return retval;
    }
}
于 2009-07-26T01:29:00.307 に答える
1

Windows が使用するのと同じツールを使用します: Windows エラー報告(WER)。クラッシュ分析を行い、クラッシュをバケット化して、最も一般的なものを理解できるようにします。コードの変更は不要で、プロセス レベルで機能します。キャッチできない例外からの失敗をログに記録します。

もちろん、すべて Windows で実行していると仮定します。

于 2009-07-25T21:48:53.783 に答える
1

私はオープン ソース プロジェクト Exceptionless に取り組んでおり、このプロジェクトにはまさにこれを行うクライアント ライブラリがあります。ハンドルされていないすべての例外をキャプチャして残りの API に送信し、リアルタイムで処理します。

https://github.com/exceptionless/Exceptionless

于 2014-12-08T20:58:16.417 に答える
1

Enterprise LibraryのLogging Application ブロックを使用すると、例外をキャッチしてログに記録するときに簡単に電子メールを送信できます。ラスト チャンス例外ハンドラの作成方法に関する情報を次に示します。あなたは Winform アプリケーションを持っていると思いますが、それはあなたの質問では明確ではありません。

于 2009-07-25T20:33:22.623 に答える
0

JeffのUser-FriendlyExceptionHandlerを変更し、.NET 2.0 / 3.5用に更新しましたが、幸運に恵まれました。例外によってスタックが処理されないままになる場合は、スクリーンショットが撮られ、詳細なスタックトレースとともに開発チームに電子メールで送信されます。

于 2009-07-26T01:33:23.970 に答える
0

ASP.NET アプリケーションで作業している場合は、ASP.NET の正常性監視機能も使用できます。構成ファイルに数行を追加すると、オフになります。 http://msdn.microsoft.com/en-us/library/bb398933.aspx

于 2009-10-01T19:03:54.933 に答える