如何解决Azure基本功能应用程序错误

时间:2019-01-02 08:24:29

标签: azure azure-functions

我在VS2017中创建了一个基本功能应用,并尝试运行 下面的问题。

  

Microsoft.Azure.WebJobs.Host:错误索引方法'Fun   章节1.运行'。 Microsoft.Azure.WebJobs.Host:无法绑定参数“ log”以键入TraceWriter。确保绑定支持参数类型。如果你是   使用绑定扩展名(例如ServiceBus,Timer等),确保已在启动代码(例如config)中调用了扩展名的注册方法。“

using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;

namespace FunctionAppLatest
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            // parse query parameter
            string name = req.GetQueryNameValuePairs()
                .FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
                .Value;

            if (name == null)
            {
                // Get request body
                dynamic data = await req.Content.ReadAsAsync<object>();
                name = data?.name;
            }

            return name == null
                ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
                : req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
        }
    }
}

1 个答案:

答案 0 :(得分:3)

Azure中的Function 2.0不再使用TraceWriter

请替换为ILogger log

您需要使用log.info代替log.LogInformation("C# HTTP trigger function processed a request.");