slipperypete
slipperypete

Reputation: 6284

How to log custom properties with Log4j to AppInsight?

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?

Upvotes: 4

Views: 1452

Answers (1)

kobulloc
kobulloc

Reputation: 259

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:

Upvotes: 1

Related Questions