You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过ASP.NET Core应用获取Azure Logic App运行与触发器历史

完全可以通过ASP.NET Core应用批量获取多个Azure Logic App的运行历史与触发器历史,推荐使用Azure官方提供的.NET SDK实现,具体方案如下:

实现前置准备
  • 首先在Azure AD中注册服务主体,为该主体分配Logic App所在订阅/资源组的Logic App Contributor角色权限,获取租户ID、客户端ID、客户端密钥三个参数备用
  • 在ASP.NET Core项目中安装两个NuGet包:Azure.ResourceManager.Logic、Azure.Identity
核心实现代码
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Logic;

public async Task GetAllLogicAppHistoriesAsync(string tenantId, string clientId, string clientSecret, string subscriptionId)
{
    // 初始化Azure资源管理客户端
    var armClient = new ArmClient(new ClientSecretCredential(tenantId, clientId, clientSecret));
    var subscription = armClient.GetSubscriptionResource(SubscriptionResource.CreateResourceIdentifier(subscriptionId));

    // 遍历订阅下所有Logic App实例,支持批量处理数十上百个实例
    await foreach (var workflow in subscription.GetLogicWorkflowsAsync())
    {
        Console.WriteLine($"正在获取Logic App:{workflow.Data.Name}的历史数据");

        // 获取该实例的运行历史
        await foreach (var runRecord in workflow.GetLogicWorkflowRunsAsync())
        {
            var runInfo = new 
            {
                RunId = runRecord.Data.Name,
                Status = runRecord.Data.Status.ToString(),
                StartTime = runRecord.Data.StartOn,
                EndTime = runRecord.Data.EndOn,
                Error = runRecord.Data.Error?.ToString()
            };
            // 可自行将数据存储到数据库或导出为文件
        }

        // 先遍历该实例下所有触发器
        await foreach (var trigger in workflow.GetLogicWorkflowTriggersAsync())
        {
            // 获取对应触发器的历史
            await foreach (var triggerHistory in workflow.GetLogicWorkflowTriggerHistoriesAsync(trigger.Data.Name))
            {
                var triggerInfo = new
                {
                    TriggerName = trigger.Data.Name,
                    Status = triggerHistory.Data.Status.ToString(),
                    FiredTime = triggerHistory.Data.StartOn,
                    Error = triggerHistory.Data.Error?.ToString()
                };
                // 可自行将数据存储到数据库或导出为文件
            }
        }
    }
}
参考截图

参考截图

注意事项
  • 接口单页默认返回最多100条历史记录,如果需要查询更早的历史,可通过接口返回的nextLink参数拉取后续分页数据。
  • 请确保注册的Azure AD服务主体权限分配正确,权限未生效时会返回403错误。

内容的提问来源于stack exchange,提问作者TDM

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.21 08:36:03