Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 505
Dan Avatar asked Dec 29 '25 11:12

Dan


1 Answers

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:

  • https://learn.microsoft.com/en-us/azure/azure-monitor/app/java-trace-logs
  • https://learn.microsoft.com/en-us/azure/azure-monitor/app/api-custom-events-metrics

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

  • Custom metrics in Azure Monitor
  • Get started with Application Insights in a Java web project
  • Explore Java trace logs in Application Insights
  • Configure Springboot Application to send log4j files to Application Insights
like image 94
kobulloc Avatar answered Jan 01 '26 04:01

kobulloc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!