gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 05:02:28 26 4
gpt4 key购买 nike

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

Microsoft.Azure.WebJobs.Host: Error indexing method 'Fun ction1.Run'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'log' to type TraceWriter. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. 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);
}
}
}

最佳答案

Azure 中的 Functions 2.0 不再使用 TraceWriter

请用ILogger日志替换

您需要使用 log.LogInformation("C# HTTP 触发器函数处理了请求。"); 而不是 log.info

关于azure - 如何解决 Azure 基本功能应用程序错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54003234/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com