Azure Function App Core v2中的应用程序见解

问题描述 投票:0回答:1

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

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

我是否缺少某些内容-将功能应用程序写入Application Insights需要什么?

azure azure-application-insights azure-function-app
1个回答
0
投票

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

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

但仅用于测试,您可以在"APPINSIGHTS_INSTRUMENTATIONKEY": "the key"中添加此行设置local.settings.json(请记住将其设置为“如果较新则复制”)。 local.settings.json中的示例设置如下所示:

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

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

© www.soinside.com 2019 - 2024. All rights reserved.