Reputation: 21308
I have a simple Azure function with HttpTrigger like so:
[FunctionName("Heartbeat")]
public async Task<IActionResult> Heartbeat(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "heartbeat")] HttpRequest req,
ILogger log)
{
log.Log(LogLevel.Information, "Received heartbeat request");
var status = await _healthCheck.CheckHealthAsync();
return new OkObjectResult(Enum.GetName(typeof(HealthStatus), status.Status));
}
local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=false",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"APPINSIGHTS_INSTRUMENTATIONKEY": "*****"
},
"ConnectionStrings": {
"ServiceDb": "Server=.;Initial Catalog=Acquire;Integrated Security=True;"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
When i run the function locally I'm able to hit a breakpoint inside Heartbeat() and get 200OK. However, when it's deployed to Azure, It does not work and I get 404 Not Found.
Local:
Azure:
What is the problem? why can't I execute an HttpTrigger?
Also, is there a way to view local.settings.json configururation in Azure? I though these settings would somehow populate from local.settings.json in Azure (like connection strings)-yet they're blank. Is there a way to show these settings in Azure?
Upvotes: 0
Views: 2180
Reputation: 21308
I found the solution. My issue was that Runtime version was set to: ~1 instead of ~3. Another change I had to make for IOptions to bind is edit project, and modify these options:
<Content Include="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
To make logging work: https://nuggets.hammond-turner.org.uk/2019/10/tuesday-quickie-ilogger-in-azure.html
I added this and now I see all logs fine:
{
"version": "2.0",
"logging": {
"logLevel": {
"ServiceLogger": "Information"
}
}
}
but all the answers from other users got me on the right path.
Upvotes: 0
Reputation: 82
There should be an option for azure to give you the function url. Should look something like this
Upvotes: 1
Reputation: 456342
is there a way to view local.settings.json configururation in Azure?
There is no local.settings.json
in Azure, hence the name "local".
You should add settings with the same names to your App Settings.
Upvotes: 2