在 QueueTrigger - Azure WebJobs SDK 3.0 中查看错误

Seeing errors in QueueTrigger - Azure WebJobs SDK 3.0

我正在将带有队列触发器的 Azure Web 作业从 2.2 升级到 3.0.4。我添加了存储扩展 Nuget 包,更改了配置代码并将应用程序获取到 运行。

它能够从队列中拉出,但我在队列触发函数中看不到任何错误,也看不到本地断点。我知道消息正在被拾取,因为它是唯一指向我的本地存储模拟器(具有唯一队列名称)的应用程序,并且所有消息在添加几秒钟后直接进入毒队列。不过,我从未在控制台中看到错误。

我使用的是 Autofac,因为 2.2 实现工作正常 - 我包含了 Autofac.Extensions.DependencyInjection 包。

这是我在 program.cs 中的主要内容 - 此处的断点很好,但在 QueueProcessor 中没有:

static void Main()
    {
        Console.ForegroundColor = ConsoleColor.Yellow;
        Console.Write("Initializing DI container...");

        var containerBuilder = new ContainerBuilder();
        RegisterTypes(containerBuilder);
        containerBuilder.RegisterType<BulkUpdateRequestProcessor>();
        containerBuilder.Build();

        Console.Write("done.");
        Console.WriteLine();
        Console.Write("Initializing host configuration...");
        var hostBuilder = new HostBuilder();
        hostBuilder.ConfigureWebJobs(b =>
        {
            b.AddAzureStorageCoreServices()
            .AddAzureStorage(options =>
             {
                 options.BatchSize = 1;
                 options.MaxDequeueCount = 1;
                 options.MaxPollingInterval = TimeSpan.FromSeconds(5f);
             });

            b.AddTimers();

            b.AddExecutionContextBinding();
            b.AddDashboardLogging();


        })
        .ConfigureServices((x) => x.AddAutofac())
        .UseConsoleLifetime();

        Console.Write("done.");
        Console.WriteLine();
        Console.ForegroundColor = ConsoleColor.Green;

        var host = hostBuilder.Build();
        using (host)
        {
            host.Run();
        }

    }

队列处理器:

public class BulkUpdateRequestProcessor
{
    private readonly IRevisionService _revisionService;

    private readonly ILogger _logger;
    private readonly IClock _clock;

    public BulkUpdateRequestProcessor(IRevisionService revisionService, ILogger logger, IClock clock)
    {
        _revisionService = revisionService;
        _logger = logger;
        _clock = clock ?? throw new ArgumentNullException(nameof(clock));
    }

    public async Task ProcessNewJobRequest([QueueTrigger(BulkUpdateConstant.BULK_UPDATE_JOB_QUEUE)] Guid jobId, TextWriter log)
    {
        _logger.Info(string.Format("New item appeared in a queue: '{0}'", jobId));

        try
        {
            await ProcessJobRequest(jobId);
        }
        catch (Exception ex)
        {
            _logger.Log(NLog.LogLevel.Error, ex);
            await TryNotifyJobFailed(jobId, ex.Message);
            throw;
        }

        _logger.Info(string.Format("Request '{0}' processed", jobId));
    }
}

事实证明,包含 Web 作业绑定的 class 需要一个零参数构造函数。我偶然发现了这一点。如果会发生构建错误,那就太好了。 -1 微软