[英]Unable to debug and publish Azure Function from Visual Studio 2017
[英]Not able to debug Azure function V4 with Timer Trigger from Visual studio 2022
我正在尝试从 Visual Studio 2022 运行/调试一个新的 Azure 函数(V4,dotnet 6.0)。该函数使用TimerTrigger
并对其进行调试,我尝试在TimerTriggerAttribute
中使用RunOnStartup = true
。 我还尝试使用来自邮递员的空请求正文{}
对http://localhost:7071/admin/functions/<functionName>
进行POST
调用。 但没有运气。 调试器不会命中该函数。
我有另一个用HttpTrigger
装饰的函数,它运行成功。 但是带有TimerTrigger
的那个没有被调用。
以下是该功能的代码和相关设置。
功能
namespace ImageAnalysisFunction
{
public class ImageAnalysis
{
[FunctionName("ImageAnalysis")]
public void Run([TimerTrigger("*/5 * * * * *", RunOnStartup = true)] TimerInfo myTimer)
{
Debug.WriteLine($"Timer triggered at: {DateTime.UtcNow}");
}
}
}
local.sttings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
}
}
启动.cs
[assembly: FunctionsStartup(typeof(ImageAnalysisFunction.Startup))]
namespace ImageAnalysisFunction
{
/// <summary>
/// Startup class to configure dependency injection, swagger and other stuff
/// </summary>
public class Startup : FunctionsStartup
{
/// <inherit />
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddLogging();
}
/// <inherit />
public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
{
base.ConfigureAppConfiguration(builder);
#if DEBUG
FunctionsHostBuilderContext context = builder.GetContext();
builder
.ConfigurationBuilder
.AddJsonFile(Path.Combine(context.ApplicationRootPath, $"appsettings.{context.EnvironmentName}.json"), optional: true, reloadOnChange: false);
#endif
}
}
}
运行时输出
Azure Functions 构建在应用服务基础结构之上。
Debug.WriteLine
方法将有关调试的信息写入 Listeners 集合中的跟踪侦听器。
如在此SO Thread中给出的, System.Diagnostics.Trace
类而不是Debug
是将日志消息添加到应用程序日志的更好方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.