Java 核心应用程序在调试时将 Application Insights 数据(日志)发送到 Azure 门户,而不是在正常应用程序上 运行

Java core application sending Application Insights data (logs) to azure portal when debugging and not on normal application run

我有一个 java 应用程序(不是网络),它定期在文件系统和控制台上记录数据。该应用程序是在 Java 中构建的,并使用 log4j-1.2。17.jar 进行日志记录。

我已将 java 应用程序配置为将日志数据发送到 Azure 的 application insights 资源。

配置涉及添加 applicationinsights-core-2.6.1.jar 和 applicationinsights-logging-log4j1_2-2.6.1.jar 以构建 java 项目的路径。 当我在调试模式下执行代码时,应用程序将日志数据发送到 azure 门户。

当我在非调试模式下执行代码时,应用程序无法将日志数据发送到 Azure 门户。 有人可以让我知道我缺少什么,以便应用程序开始以正常模式(非调试)向门户发送数据。

据此documentation

Telemetry is not sent instantly. Telemetry items are batched and sent by the ApplicationInsights SDK. In Console apps, which exits right after calling Track() methods, telemetry may not be sent unless Flush() and Sleep/Delay is done before the app exits as shown in full example later in this article.

您可以添加一个 flush() 和 sleep() 方法来使 try.It 可以是您的应用程序已结束,但遥测数据尚未发送。

希望对您有所帮助。