如何在最新的Azure Webjob 3.03中指定AzureWebJobsStorage [英] How to specify AzureWebJobsStorage in latest azure webjob 3.03

查看:454
本文介绍了如何在最新的Azure Webjob 3.03中指定AzureWebJobsStorage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将旧的Azure Web作业代码更新为3.03,然后无法正常工作.

I updated my old azure webjob code to package to 3.03 and then it is just not working.

我设法解决了所有编译时错误,但是在本地运行时会引发以下错误:

I managed to fix all compile-time errors, but when running locally, it throws this error:

Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException
  HResult=0x80131500
  Message=Error indexing method 'MvQueueProcessorV2.ProcessMVRequest'
  Source=Microsoft.Azure.WebJobs.Host
  StackTrace:
   at Microsoft.Azure.WebJobs.Host.RecoverableException.TryRecover(ILogger logger) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Exceptions\RecoverableException.cs:line 81
   at FE.Toolkit.MvPaaS.WebJob.Program.<Main>(String[] args)

Inner Exception 1:
InvalidOperationException: Storage account 'Storage' is not configured.

对我来说,这似乎表明它找不到设置 AzureWebJobsStorage ?但是,它可以很好地睡在app.config文件中.所以我假设我应该将连接字符串放到appsettings.json中,所以这就是我在appsettings.json中所做的:

For me, this seems to indicate that it can't find setting AzureWebJobsStorage? However, it sleeps nicely in the app.config file. So I assumed that I should put my connection string to appsettings.json, so this is what I did in my appsettings.json:

{
  "ConnectionStrings": {
    "AzureWebJobsDashboard": "xxx",
    "Storage": "yyy"
  }
}

但是,它给了我同样的错误.那么如何为webjob 3.0设置存储空间?

However, it gives me the same error. So how do I set storage for webjob 3.0?

这是我在program.cs中的代码

This is my code in program.cs

var builder = new HostBuilder()
              .UseEnvironment("Development")
              .ConfigureWebJobs(b =>
               {
                 b.AddAzureStorageCoreServices()
                   .AddAzureStorage()
                   .AddTimers()
                   .AddFiles()
                   .AddDashboardLogging();
                   })
                  .ConfigureLogging((context, b) =>
                 {
                   b.SetMinimumLevel(LogLevel.Debug);
                   b.AddConsole();
                  })
                   .ConfigureServices(services =>
                  {
                        services.AddSingleton<INameResolver, ConfigNameResolver>();
                  })
               .UseConsoleLifetime();

推荐答案

请在您的program.cs中添加以下代码行:

Please add this line of code in your program.cs:

.ConfigureAppConfiguration((context, config) => {
                    config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
                })

我已经在身边进行了测试,并且工作正常.

I have tested at my side, and works fine.

Program.cs中的代码:

code in Program.cs:

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace WebJob1template
{
    class Program
    {
        static void Main()
        {

            var builder = new HostBuilder()
                .UseEnvironment("Development")
                .ConfigureAppConfiguration((context, config) => {
                    config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
                })
                .ConfigureWebJobs(
                b =>
                {
                    b.AddAzureStorageCoreServices()
                    .AddAzureStorage()
                    .AddTimers()
                    .AddFiles();
                    //.AddDashboardLogging();
                })
                .ConfigureLogging((context, b) =>
                {
                    b.SetMinimumLevel(LogLevel.Debug);
                    b.AddConsole();
                })
                .UseConsoleLifetime();


            var host = builder.Build();

            using (host)
            {
                host.Run();
            }
        }
    }
}

appsettings.json(请注意,将其属性复制到输出目录"设置为始终复制"):

appsettings.json(note that set it's property "Copy to Output Directory" as Copy always):

{
  "ConnectionStrings": {
    "AzureWebJobsDashboard": "xxxx",
    "AzureWebJobsStorage": "xxxx"
  }
}

Function.cs:

Function.cs:

using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;

namespace WebJob1template
{
    public class Functions
    {        
        public static void ProcessQueueMessage([QueueTrigger("queue")] string message, ILogger log)
        {
            //log.WriteLine(message);
            log.LogInformation(message);
        }
    }
}

测试结果:

这篇关于如何在最新的Azure Webjob 3.03中指定AzureWebJobsStorage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆