Azure Function App Core v2中的应用程序见解 [英] Application Insights in Azure Function App Core v2

查看:70
本文介绍了Azure Function App Core v2中的应用程序见解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用标准的ILogger并将其记录到Azure.首先,我在主机文件中添加了以下内容:

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"
  }
}

这是我的功能:

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}");            
        }
    }
}

但未添加任何日志记录.我也尝试安装nuget软件包:Microsoft.Extensions.Logging.ApplicationInsights

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

我是否想念一些东西-将功能应用程序写入Application Insights需要做什么?

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

推荐答案

我认为您是利用应用程序见解在本地运行azure函数,对吧?

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

如果是,实际上不建议这样做,因为应用程序见解已与Azure门户中的Azure功能集成在一起.

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

但仅出于测试目的,您只需在 local.settings.json 中添加以下行设置"APPINSIGHTS_INSTRUMENTATIONKEY":密钥" (请记住,将其设置为如果较新则复制"). local.settings.json 中的示例设置如下所示:

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"
  }
}

顺便说一句,我还在测试中安装了nuget包 Microsoft.Extensions.Logging.ApplicationInsights .

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

这篇关于Azure Function App Core v2中的应用程序见解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆