Azure函数表绑定产生大量日志噪声



刚刚将azure功能从v3升级到v4和dotnet6。注意,运行时绑定也需要更新。

我刚刚对它进行了测试,并注意到有很多详细的日志记录来自Table绑定以及我自己的日志记录。我怎么能排除这个呢?我应该排除它吗?当看到一根活的原木时,很难从树上看到木头

[FunctionName("Function2")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
[Table("Keys", Connection = "TableStorage")] TableClient keysTable,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");

if (keysTable != null)
{
try
{
var item2 = keysTable.GetEntity<TableEntity>("jon", "test");  
}
catch (Exception)
{
log.LogError("key not present");
}
}
log.LogInformation("C# HTTP trigger function completed.");
return new OkObjectResult(new { });
}

日志输出

2022-12-28T12:40:14Z   [Information]   Request [6b093468-5e75-4e8c-b358-e47f0dffc632] POST https://xxx.table.core.windows.net/Tables?$format=REDACTED
x-ms-version:REDACTED
DataServiceVersion:REDACTED
Prefer:REDACTED
Accept:application/json; odata=minimalmetadata
x-ms-client-request-id:6b093468-5e75-4e8c-b358-e47f0dffc632
x-ms-return-client-request-id:true
User-Agent:azsdk-net-Data.Tables/12.7.1,(.NET 6.0.11; Microsoft Windows 10.0.14393)
x-ms-date:REDACTED
Authorization:REDACTED
Content-Type:application/json; odata=nometadata
client assembly: Azure.Data.Tables
2022-12-28T12:40:14Z   [Information]   Response [6b093468-5e75-4e8c-b358-e47f0dffc632] 409 Conflict (00.0s)
Cache-Control:no-cache
Transfer-Encoding:chunked
Server:Windows-Azure-Table/1.0,Microsoft-HTTPAPI/2.0
x-ms-request-id:e63cd248-2002-0051-25b9-1ae043000000
x-ms-client-request-id:6b093468-5e75-4e8c-b358-e47f0dffc632
x-ms-version:REDACTED
X-Content-Type-Options:REDACTED
Preference-Applied:REDACTED
Date:Wed, 28 Dec 2022 12:40:13 GMT
Content-Type:application/json; odata=minimalmetadata; streaming=true; charset=utf-8
2022-12-28T12:40:14Z   [Information]   Executing 'Function2' (Reason='This function was programmatically called via the host APIs.', Id=3598edde-1658-414b-9cc4-481bb6f7810e)
2022-12-28T12:40:14Z   [Information]   C# HTTP trigger function processed a request.,

我以为只有我的日志会出现。

我通读了这篇文章,发现了这条信息

https://learn.microsoft.com/en-us/azure/azure-functions/functions-monitoring disable-built-in-logging

依赖性从版本2开始。Application Insights会自动收集使用特定客户端sdk的绑定的依赖关系数据。在一个孤立的工作进程中运行的c#应用目前不支持分布式跟踪和依赖项跟踪。Application Insights收集以下依赖项的数据:

Azure Cosmos DB
Azure Event Hubs
Azure Service Bus
Azure Storage services (Blob, Queue, and Table)

没有说明如何禁用

主机。json文件

{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
}
}

更新host.json文件中只包含这些类别的错误日志,

{
"version": "2.0",
"logging": {
"logLevel": {
"default": "Information",
"Azure.Core": "Error",
"Azure.Messaging.ServiceBus": "Error"
//others categories you have noise
}
}
}

您给出的host.json代码将记录/捕获在请求和响应期间到来的实时数据。
正如@AnandSowmithiran所说,有一个属性loglevel定义了运行Function App时所需的日志集合。

您必须在发布功能项目之前将logLevel属性添加到host.json,该属性设置的值如日志级别InformationErrorTrace日志级别分为两类:功能日志和主机日志。

参考@HariKrishna给出的SO Q&A 70683888,关于Azure功能日志级别设置信息以及优化重日志以最小化Monitor定价。

最新更新