如何使用Log4j将自定义属性记录到AppInsight?

huangapple go评论65阅读模式
英文:

How to log custom properties with Log4j to AppInsight?

问题

我已在网上和Stack Overflow上寻找了这个问题的答案。但我没有看到任何答案,所以想知道是否可能。我想使用log4j并将日志数据格式化为JSON发送到Azure的服务AppInsight中。我可以将JSON数据发送到那里,但它以纯文本形式显示。我看到可以使用遥测来处理这种情况,但我不想涉及那部分。我只希望log4j来处理我的日志记录。将JSON日志记录到Azure的AppInsight中并使其能够识别为JSON,然后使其数据可查询,这是否可能?如果可能,该如何实现?

英文:

I have looked online and on SO for the answer to this question. And I am not seeing any answers so wonder if it is possible. I want to use log4j and log data formatted in JSON to azure's service AppInsight. I can get the json data there ok, but It comes in as raw text. I have seen that it is possible to use Telemetry for this use case but I don't want to mess with that. I just want log4j to handle my logging. Is it possible to log JSON to azure's AppInsight and have it recognize it as json and then make it's data queryable? If so, how?

答案1

得分: 1

抱歉,这将会有一些链接内容,但根据您的要求,我将仅提供已翻译的文本部分:

有关 Application Insights 功能的一些相对较新的更改以及它与 Azure Monitor 的关系,旨在整合和澄清这些服务的角色。现在,大部分涵盖数据收集器 API 和跨资源日志查询等内容的 Application Insights 文档都会将您引导到 Azure Monitor。因此,一些 Application Insights 的功能已被停用:

对于您描述的情况,您应该使用 Azure Monitor。您仍然可以在 Application Insights 中导入您的 log4j 文件,如果需要,您可以利用 Application Insights API 进行自定义事件和指标:

以下是一些有用的链接,如果您想了解更多:

英文:

Forgive me, this is going to be a bit link heavy but you have different options depending on what you want to do so I'm trying to include as much information as possible here.

There have been some relatively recent changes to Application Insights features and its relationship to Azure Monitor in an effort to consolidate and clarify the roles of the services. Most of the Application Insights documentation that covers things like the Data Collector API and cross-resource log queries now sends you to Azure Monitor. Accordingly, some of Application Insights functionality has been retired:

https://azure.microsoft.com/en-us/blog/analyze-your-data-with-application-insights-analytics/

> "The functionality described in this blog was retired and no longer
> exist in Application Insights. Alternatively, you can send your
> custom log to the Azure Monitor log store, which is Log
> Analytics. You can query this data from Log Analytics or your
> Application Insights resource using cross-resource queries."

So for the scenario you described, you would want to use Azure Monitor. You are still able to import your log4j files in Application Insights and you can leverage the Application Insights API for custom events and metrics if you would like:

Here are some useful links if you'd like to learn more:

huangapple
  • 本文由 发表于 2020年8月15日 07:07:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/63421001.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定