1
votes

I am working on my first project on Application Insights and facing some issues.

Tech Stack

Project Type - Azure Durable Functions

.NetStandard 2.0

Visual Studio 2017

Problem

In the HTTPStart method, I add a custom log message using ILogger (and TraceWriter).

Sample Code

log.LogInformation("******* Test Message********");

When I am running application on my local, host file is as:

{
  "version": "2.0",
  "logger": {
    "categoryFilter": {
      "categoryLevels": {
        "Host.Triggers.DurableTask": "Information"
      }
    }
  }

}

With this background, I am trying to figure out the following issues:

  1. Custom Logs not seen on Azure Portal. Application Insights Key Configured in the slot's application settings

The problem is, I can see generic statements (out of the box) being logged but the custom log with the help of ILogger / TraceWriter are not being shown.

  1. Unable to see any logs on local I wanted to see logging on my local system so that I don't have to deploy on Azure every time, I need to test logging on exceptional scenarios. I cant' see any logs on VS2017. Application insights on VS2017
1
For the 2nd issue, when you run the code locally, have you added the application insights package?Ivan Yang
@IvanYang - Yes I haveTarun Bhatt
You don't need to publish it to azure. even if it runs locally, the logs can also be sent to application insights.Ivan Yang
@IvanYang - Yes you are right. Before I was not able to send logs to App insights from my local. But it started working the moment I logged in from my home network and not on my office network. This gives me an impression that its due to the way Azure function simulator handles proxy issue.Tarun Bhatt
But the problem now is even after deploying the azure function on Azure, I cant see custom logs, even though OOTB logs from Azure durable can be seen.Tarun Bhatt

1 Answers

2
votes

Update:

In you function app -> Monitor blade, If anything is ok, you should see application insights logs there. like the screenshot below: enter image description here

The following is my code: enter image description here

The following is my host.json by default:

{
    "version": "2.0"
}

The following is my application settings in portal: enter image description here

and after I publish it to azure, and I can see the custom logs writing by ILogger is shown in azure portal -> application insights(it may take a few minutes): enter image description here

Just for the 2nd issue, For console app or similar project, the "Application Insights Search" function is not available.

I install Microsoft.ApplicationInsights 2.8.1, and add the following two custom logs:

[FunctionName("Function1_Hello")]
public static string SayHello([ActivityTrigger] string name, ILogger log)
{
   log.LogInformation($"Saying hello to {name}.");
   log.LogInformation("xxxxxx ssssssss wwwwwwww");
   return $"Hello {name}!";
}

There are 2 ways to see them(do not need to publish to azure):

1.Nav to azure portal -> app insights -> search , and it may take a few minutes to show them: enter image description here

2.In visual studio output window, it can show asap: enter image description here