0

I am trying to use the standard ILogger and make it log to Azure. First I added following to host file:

{
  "version": "2.0",
  "Logging": {
    "ApplicationInsights": {
      "LogLevel": {
        "Default": "Trace",
        "System": "None",
        "Microsoft": "None"
      }
    }
  },
  "ApplicationInsights": {
    "Instrumentationkey": "xx-xx-xx-xx-xx"
  }
}

And this is my function:

namespace Jobs
{
    public static class ExchangeRates
    {
        [FunctionName("ExchangeRates")]
        public static void Run([TimerTrigger("0 0 0 * * *", RunOnStartup =true)]TimerInfo myTimer, ILogger log)
        {
            string lol1 = "lol1 text";
            string lol2 = "lol2 text";

            log.LogWarning("adsad");
            log.LogDebug("LogDebug", "asdasd", lol2);
            log.LogTrace("LogTrace {lol1}, {lol2}", lol1, lol2);
            log.LogInformation("LogInfo {lol1}, {lol2}", lol1, lol2);
            log.LogError("LogError");
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");            
        }
    }
}

But no logging are added. I also tried installing nuget package: Microsoft.Extensions.Logging.ApplicationInsights

Am I missing something - what does it take to make an function app writing to Application Insights?

huysmania
  • 1,054
  • 5
  • 11
Thomas Segato
  • 4,567
  • 11
  • 55
  • 104

1 Answers1

0

I think you're running the azure function locally with application insights, right?

If yes, actually it's not recommended since application insights is integrated with azure function in azure portal.

But for testing only, you can just add this line of setting "APPINSIGHTS_INSTRUMENTATIONKEY": "the key" in local.settings.json(remember to set it as "copy if newer"). The sample settings in local.settings.json looks like below:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "xxxxxx",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "APPINSIGHTS_INSTRUMENTATIONKEY": "the key"
  }
}

By the way, I also installed the nuget package Microsoft.Extensions.Logging.ApplicationInsights in my test.

Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60