我已从 azure 中的常规 Azure 函数应用迁移到 AKS。 我已将 Instrumentation Key 添加到我们的清单/头盔图表中。 我还可以在“事务搜索”和“性能”选项卡中查看请求日志和错误,但记录的错误和异常不会最终出现在“失败”选项卡中。
有人遇到过同样的问题吗?或者可能是什么问题? 我很高兴能得到任何帮助。 干杯。
host.json 文件:
{
"version": "2.0",
"logging": {
"logLevel": {
"default": "Information",
"Host": "Error",
"Function": "Error",
"Host.Results": "Information",
"Host.Aggregator": "Error"
},
"applicationInsights": {
"samplingExcludedTypes": "Request",
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Exception"
}
}
}
}
我尝试将 host.json 文件更改为许多不同的设置,但我真的不认为这是问题所在。
编辑:我将我设置的新应用程序洞察与针对我们的常规 azure 功能应用程序设置的应用程序洞察进行了比较。新的应用程序洞察力似乎与日志分析有关,这可能是问题所在吗?
这对我有用。
host.json
:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
},
"enableLiveMetricsFilters": true
}
}
}
Function1.cs
using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
namespace FunctionApp1
{
public class Function1
{
private readonly ILogger _logger;
public Function1(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<Function1>();
}
[Function("Function1")]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req)
{
_logger.LogError(new Exception("something wrong"), "TestLog ErrorWithException");
var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
response.WriteString("Welcome to Azure Functions!");
return response;
}
}
}
OUTPUT
: