c# - Azure WebJobs 未找到函数

标签 c# .net azure azure-webjobs

程序.cs:

    public static void Main(string[] args)
    {
        var builder = new HostBuilder()
            .ConfigureLogging((context, b) =>
            {
                b.SetMinimumLevel(LogLevel.Debug);
                b.AddConsole();
            })
            .UseConsoleLifetime();

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

函数.cs:

public class Functions
{
    private readonly ISampleServiceA _sampleServiceA;
    private readonly ISampleServiceB _sampleServiceB;

    public Functions(ISampleServiceA sampleServiceA, ISampleServiceB sampleServiceB)
    {
        _sampleServiceA = sampleServiceA;
        _sampleServiceB = sampleServiceB;
    }

    public static void RunSomething([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, ILogger log) // every one minute
    {
        if (myTimer.IsPastDue)
        {
            log.LogInformation("Timer is running late!");
        }
        log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
    }
}

当我运行时,我得到:

dbug: Microsoft.Extensions.Hosting.Internal.Host[1]
      Hosting starting
dbug: Microsoft.Extensions.Hosting.Internal.Host[2]
      Hosting started

我已经阅读了几个示例,我的印象是,通过创建新的控制台应用程序、引用所需的程序集并包括上述内容,WebJob 应该“正常工作”。我是否遗漏了一些关键配置?

版本:

enter image description here

最佳答案

您在配置中缺少 AddTimers(),因为它是一个时间触发函数。

请为您的项目安装包Microsoft.Azure.WebJobs.Extensions,然后在您的program.cs中 -> Main方法:将AddTimers添加到webjob配置中,如下所示:

                var builder = new HostBuilder()
                .ConfigureWebJobs(
                b =>
                {
                    b.AddTimers();
                    //other configure
                })
                .ConfigureLogging((context, b) =>
                {
                    b.SetMinimumLevel(LogLevel.Debug);
                    b.AddConsole();
                })
                // your other configure
                .UseConsoleLifetime();

也可以引用我的previous answer有关 webjob 3.x 的更多配置。

关于c# - Azure WebJobs 未找到函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54525272/

相关文章:

c# - 将存储在对象中的 Enum 数据绑定(bind)到 Winforms ComboBox 中?

c# - 如何在 Log4Net 中记录运行时间

bash - Azure Pipelines 的 YAML 文件中的 Echo 打印不同的内容

azure - Windows Azure 和 WCF 数据服务 V3

c# - 如何从类构造函数中捕获事件触发

c# - LINQ lambda 表达式中的 Where 条件

c# - 在我在 Visual Studio 2017 中生成的文件中添加 "Generated"关键字

.net - .NET 集合类的渐近复杂性

azure - 我使用 Azure 搜索,而 Azure 搜索又使用 Lucene。有没有办法可以搜索此查询 : colo? r 这将导致获得 "color"和 "colour"值?

c# - 如何为通过 Exchange Server 发送的邮件设置 MHT-body?