Search code examples
azureazure-functionsazure-functions-core-tools

Why Azure Functions doesn't show exceptions in debugger?


I am new to Azure Functions and I found that while debugging if my code hit some exception it doesn't show in the debugger (I am using Visual Studio 2019). Also it just logs the exception without stack trace info so it becomes hard to figure out the bug. Right now I am using try catch block and logging the stack trace like this-

try
{
    var LoginWithCustomIdAsync = await PlayFabClientAPI.LoginWithCustomIDAsync(new LoginWithCustomIDRequest
    {
        CustomId = Data.CallerEntityProfile.Entity.Id,
                TitleId = Data.TitleAuthenticationContext.Id
    });

}
catch (Exception e)
{
    log.LogInformation(e.Message+"--"+e.StackTrace);
}

but I want a better solution. Right now I am running my azure function locally. So is there anything I am missing?

host.json code

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true
      }

    }
  }

}

Solution

  • I solved it, So what I found that I need to change exception setting in order to get the exception in visual studio and to get exception for running azure function on web you need to add application insight NuGet package and also setup application insight on web. Then the exception will show in the Application insight Failures window

    Vs studio Exception setting

    Application insight Failures window