共用方式為


Trace 函數

適用於: 畫布應用程式 Copilot Studio 模型導向應用程式 Power Platform CLI Dataverse 函數

應用程式幕後通常會有許多邏輯在運作。 影響有時很明顯 (例如控制項的值或色彩變更),確認邏輯在正確運作。 不過,有時並不明顯,可能很難具體呈現和了解應用程式中發生的情況。 使用此功能 Trace 從幕後記錄診斷資訊,建立實際發生情況的時間表,以進一步瞭解應用程式的運作方式,並協助偵錯問題。

在 Power Apps 中使用時,輸出 Trace 會與其他應用程式活動一起出現在 Power Apps 監視器 工具中。 如果您已允許應用程式將遙測資料傳送至 Azure Application Insights,則函 Trace 式也可以用來將資訊傳送至 Application Insights 資源。 Trace 只能用於 行為公式

Test Studio 搭配使用時, Trace 是選用運算式,可用來在 OnTestCaseComplete 事件的測試結果中提供其他資訊。 Trace事件訊息會與 TestCaseResult 記錄的 Traces 資料表中通過和失敗的判斷提示訊息結合。 Traces 資料表有 MessageTimestamp 這兩個屬性。 Trace 測試中使用的資訊也會記錄在 Application Insights 中。 從 Power Apps Studio 播放應用程式時,監視器會連接至應用程式,因此將無法在監視器工具中使用測試追蹤資訊。

語法

Trace訊息 [, TraceSeverity [, CustomRecord [, TraceOptions ] ] ] ) )

  • Message –必需。 要追蹤的資訊。 數字、日期、布林值以及任何其他可強制轉型成文字的資料類型。
  • TraceSeverity —可選。 監視器和 Application Insights 中記錄的嚴重 Trace 性層級。 選項有 TraceSeverity.Information (預設)、TraceSeverity.WarningTraceSeverity.ErrorTraceSeverity.Critical
  • CustomRecord –可選。 包含要記錄在監視器或 Application Insights 中的自訂資料的記錄。
  • TraceOptions –可選。 選項有 TraceOptions.None (預設) 和 TraceOptions.IgnoreUnsupportedTypes (這會忽略 CustomRecord 中無法序列化的資料類型)。

範例

  1. 在 Power Apps Studio 中建立按鈕控制項。
  2. OnSelect 公式設定為公式:
Set( x, x+1 );
Trace( x );
  1. 在另一個瀏覽器視窗中開啟 Power Apps 監視器,方法是選取左窗格中的 [進階工具] 圖示,然後選取 [開啟監視器]:Power Apps 監視器的進入點
  2. 返回原始工作室瀏覽器視窗,並選取按鈕四次。 如果是在設計模式中,請使用滑鼠按住 Alt 鍵再按一下
  3. 檢視 Power Apps 監視器。
  4. 監視器的網格將包含每次按鈕點擊和每次 Trace 呼叫的事件,該事件將在每次增量後顯示變數的值。 切入事件 Trace 以查看啟動的位置 Trace ,以及用於訊息的運算式,在右側面板中: 監視器追蹤顯示按下四次按鈕和變數的相應增量

另請參閱

Power Apps Monitor 概述
Test Studio 概述
使用 Test Studio