问题
In the following code, where is the error logged in Azure? Sometimes the cause of such an error is difficult to identify, and results in "Function host is not running.", I've not been able to find the logged exception.
I've worked around this before by writing my own try/catch logging to BlobStorage myself, however, I'd hope there's a more idiomatic way of obtaining the exception.
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
throw new Exception("Boom!");
ConfigureServices(builder.Services);
}
...
I've looked in the following places:
Diagnose and solve problems / Function App Down or Reporting Errors:
- Reports a stale error, doesn't seem to be updated each time the above error is raised.
AppInsights:
- "Your app is offline or the Application Insights SDK needs updating."
Kudu:
- D:\home\LogFiles\eventlog.xml - Can't see anything meaningful here
- D:\home\LogFiles\Application\Functions\Function\FunctionName\*.log - No files for today
- D:\home\LogFiles\Application\Functions\Host\*.log - No files for today
Storage account file shares:
- One modified with today's date
- /LogFiles/ - Empty
- /site/wwwroot/ - Empty
回答1:
You can check the exception logs from Startup.cs as per steps below.
First, this is my test code:
[assembly: FunctionsStartup(typeof(FunctionApp11.Startup))]
namespace FunctionApp11
{
public class Startup: FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
throw new Exception("xxxx haha an error is occuring....");
}
}
}
After the azure function running in azure portal, please follow these steps:
Step 1. Nav to azure portal -> your function app -> click on the Diagnose and solve problems blade -> Then input function app down in the search box -> then you can see Function App Down or Reporting Errors appears, click on it. The screenshot as below:
Step 2. In the Function App Down or Reporting Errors page, expand Function Executions and Errors -> then expand Detected host offline in your function app. -> at last, you can see the exception logs there(if no error logs, consider to change the time range in the page). The screenshot as below:
来源:https://stackoverflow.com/questions/62657579/where-can-exceptions-raised-within-functionsstartup-configure-be-found-logged-on