ILogger如何记录到Azure Application Insights?

时间:2018-04-30 11:47:44

标签: azure azure-functions azure-application-insights

在Azure功能中,当您向Application Insight启用遥测并触发(例如)logger.LogInformation调用(其中loggerILogger实例)时,它是否将其发送到Application Insight实例是异步(即非阻塞),同步(阻塞)还是通过异步耗尽的本地日志?

2 个答案:

答案 0 :(得分:2)

通常,将连接记录器以将日志调用转换为Application Insights SDK中的各种trackMessage或相关调用。这些消息在AI端进行批处理,然后在满足消息的阈值计数后或在经过一定时间后发送。对应用程序见解的调用都是非阻塞的,不会抛出异常(你不希望遥测对你的真实应用产生负面影响!)

azure函数将使用的c#sdks将在这里:https://github.com/Microsoft/ApplicationInsights-dotnet/

我在顶部说一般,因为所有这些都取决于SDK的配置方式,而这取决于Azure功能底层代码。 GitHub及其信息在这里:https://github.com/Azure/Azure-Functions,他们也有一个特定的wiki设置了AI信息,在这里:https://github.com/Azure/Azure-Functions/wiki/App-Insights

答案 1 :(得分:1)

这似乎是专门如何将数据发送到Application Insights的相关代码:

https://github.com/Microsoft/ApplicationInsights-dotnet/tree/develop/src/Microsoft.ApplicationInsights/Channel

ILogger包裹TelemetryClientITelemetryChannel将数据发送到InMemoryTelemetryChannel

new File("t.dat").length()包含如何汇总数据并将其发送到Application Insights的逻辑。正如约翰所提到的,该频道使用了一个"缓冲区"用于存储尚未发送的数据。当缓冲区已满或在内部特定时间(30秒)时,刷新缓冲区并将数据异步发送到Azure Portal。

相关问题