在企業級工作流應用中,完整的審計追蹤、性能監控與故障診斷能力至關重要。SqlTrackingService 作為 WF 內置的企業級追蹤服務,能將運行時事件、活動執行軌跡、數據變更等關鍵信息持久化到 SQL Server,為合規審計與問題排查提供堅實基礎。
實現 IPendingWork 接口,參與 WorkflowCommitWorkBatchService 的批次事務處理。通過 IsTransactional 屬性控制,確保追蹤數據與工作流狀態的原子性提交,避免數據不一致。
實現 IProfileNotification 接口,定期輪詢數據庫中的 TrackingProfile 變更(間隔由 ProfileChangeCheckInterval 控制),熱更新追蹤配置無需重啟宿主進程。
執行框架目錄下的腳本(順序不可逆):
C:\WINDOWS\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\EN\Tracking_Schema.sql — 建表結構Tracking_Logic.sql — 建立存儲過程、視圖與索引<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="WorkflowWithTracking"
type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection,
System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
</configSections>
<WorkflowWithTracking>
<CommonParameters>
<add name="ConnectionString"
value="Data Source=.;Initial Catalog=c6ps;Integrated Security=True"/>
</CommonParameters>
<Services>
<add type="System.Workflow.Runtime.Tracking.SqlTrackingService,
System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
</Services>
</WorkflowWithTracking>
</configuration>
IsTransactional="true" 確保數據一致性ProfileChangeCheckInterval(建議 30-60 秒)TrackingProfile 只記錄關鍵業務節點,減少存儲開銷