プラグインで ITracingService を使用する

カテゴリ: 保守性、サポート

影響の可能性: 中程度

現象

プラグインの問題や動作のデバッグやトラブルシューティングは、豊富で洞察に満ちたログやトレースがなければ複雑となります。

ガイダンス

ITracingService インタフェースは、コードの失敗やプラグインの予期しない動作の原因を診断するために、ランタイム カスタム情報を記録することで開発者を支援します。 トレース サービスに書き込む前に、まず渡された実行コンテキストからトレース サービス オブジェクトを抽出する必要があります。 その後、トレース 呼び出しをカスタム コードに追加するだけです。適切な場合は、そのメソッド呼び出しに関連する診断情報を渡します。

注意

ITracingService インターフェースを使用したトレース ロギングは、プラグインがサンドボックス モードで登録されている場合にのみ機能します。ランタイム データを取得するにはトレース ロギングを有効にする必要があります。 詳細については、ロギングとトレース を参照してください。

//Extract the tracing service for use in debugging sandboxed plug-ins.
ITracingService tracingService =
    (ITracingService)serviceProvider.GetService(typeof(ITracingService));

// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)
    serviceProvider.GetService(typeof(IPluginExecutionContext));

// For this sample, execute the plug-in code only while the client is online. 
tracingService.Trace("AdvancedPlugin: Verifying the client is not offline.");
if (context.IsExecutingOffline || context.IsOfflinePlayback)
    return;

// The InputParameters collection contains all the data passed 
// in the message request.
if (context.InputParameters.Contains("Target") &&
    context.InputParameters["Target"] is Entity)
{
    // Obtain the target entity from the Input Parameters.
    tracingService.Trace("AdvancedPlugin: Getting the target entity from Input Parameters.");
    Entity entity = (Entity)context.InputParameters["Target"];

    // Obtain the image entity from the Pre Entity Images.
    tracingService.Trace("AdvancedPlugin: Getting image entity from PreEntityImages.");
    Entity image = (Entity)context.PreEntityImages["Target"];
}

追加情報

登録されたカスタム コードはそのシナリオでサポートされている唯一のトラブルシューティング方法であるため、トレースは登録されたカスタム コードのトラブルシューティングに特に役立ちます。 トレースは、サンドボックスで保護された sandboxed (部分信頼)、また完全信頼で登録されたユーザー定義コードに対して、同期または非同期の実行時にサポートされます。 トレースは、Microsoft Dynamics 365 for Outlook または他のモバイル クライアントで実行されるカスタム コードではサポートされていません。

関連項目

プラグインを記述する
トレースおよびログ

注意

ドキュメントの言語設定についてお聞かせください。 簡単な調査を行います。 (この調査は英語です)

この調査には約 7 分かかります。 個人データは収集されません (プライバシー ステートメント)。