Tarun Bhatt
Tarun Bhatt

Reputation: 817

Custom logs are not visible using Application Insights

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

Upvotes: 1

Views: 3671

Answers (1)

Ivan Glasenberg
Ivan Glasenberg

Reputation: 29940

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

Upvotes: 2

Related Questions