问题描述
使用 Spring Cloud Functions 实现了 Azure Functions 应用程序。在应用设置“APPINSIGHTS_INSTRUMENTATIONKEY”中配置的 App Insights 检测密钥:。 我使用 lombok 注释 @Slf4j 来记录消息,但我无法在 App 洞察中看到它们。应用程序洞察仅捕获使用 ExecutionContext 日志编写的日志。 任何人都可以给我一个参考 ho 使用 slf4j 在 App Insights 中记录消息。
解决方法
如果您使用的是 AppInsights 2.x,则可以使用 applicationinsights-logging-logback
或 applicationinsights-logging-log4j2
库来启用日志记录。请阅读 recipe from old python version 以了解有关启用日志的更多信息。
<!-- Logback -->
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>applicationinsights-logging-logback</artifactId>
<version>[2.0,)</version>
</dependency>
</dependencies>
<!-- Log4J 2.0 -->
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>applicationinsights-logging-log4j2</artifactId>
<version>[2.0,)</version>
</dependency>
</dependencies>
如果您使用的是 AppInsights 3.x,您可以documentation,它会自动将日志导出到 App Insights。
还有一个 configure the agent 可以启用分布式跟踪,可从 Azure 门户启用。