Solr to Application Insights

2019-07-25 21:14发布

How can I configure Solr logs to get sent to Azure Application Insights?

I see can use a Log4J appender. https://docs.microsoft.com/en-us/azure/application-insights/app-insights-java-trace-logs

Solr is an open source project, and I don't compile it myself, I just use the distribution.

How can I drop in Application Insights/Log4J appender, without recompiling having installed the SDK? I just want to configure the logs to get sent to application insghts, for effectively a 3rd party application. And configure the instrumentation key.

I'm normally a C# dev, but familiar with Log4Net. So appologies if this is simple in Java Log4J. Not been able to find a post for this scenario so posting here.

Using Solr 6.6.

1条回答
Bombasti
2楼-- · 2019-07-25 21:40

It takes a lot less configuration than you'd expect, and most of the info is hidden away in the link that you've already got: https://docs.microsoft.com/en-gb/azure/azure-monitor/app/java-trace-logs

First, go download the jar files from https://github.com/Microsoft/ApplicationInsights-Java/releases. You'll want applicationinsights-logging-log4j1_2-2.3.0 and applicationinsights-core-2.3.0. Put these in the server/lib folder and Solr will load them automatically for you.

Next you''ll need to add a new appender for app insights into your log4j.properties file

# Appinsights
log4j.appender.aiAppender=com.microsoft.applicationinsights.log4j.v1_2.ApplicationInsightsAppender
log4j.appender.aiAppender.layout=org.apache.log4j.EnhancedPatternLayout
log4j.appender.aiAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%X{collection} %X{shard} %X{replica} %X{core}] %c{1.} %m%n

You also need to add this aiAppender to the log4j.rootLogger list in the same file (it'll probably look something like this: log4j.rootLogger=INFO, file, CONSOLE, aiAppender)

Finally, you need an ApplicationInsights.xml file, which you can get an example of from here https://docs.microsoft.com/en-gb/azure/azure-monitor/app/java-get-started#2-add-the-application-insights-sdk-for-java-to-your-project

Drop this in the server/resources folder, set your instrumentation key and you're good to go!

查看更多
登录 后发表回答