Application Insights Logging In MuleSoft

Authors: Subrath Kumar & Indresh Gupta

  • Initially log into your Microsoft Azure portal 
  • Search for application insights in the search box
  • Create a new resource/project in application insights and fill all the fields
  • Open the application insight project and copy the instrumentation key 
  • Open the project in anypoint studio and add the following dependencies in  POM file inside dependencies tag.
         <!-- Application Insights dependencies. -->
		<dependency>
			<groupId>com.microsoft.azure</groupId>
			<artifactId>applicationinsights-logging-log4j2</artifactId>
			<version>2.6.3</version>
		</dependency>
		<dependency>
			<groupId>com.microsoft.azure</groupId>
			<artifactId>applicationinsights-web</artifactId>
			<version>2.6.3</version>
		</dependency>
		<dependency>
			<groupId>com.microsoft.azure</groupId>
			<artifactId>applicationinsights-core</artifactId>
			<version>2.6.3</version>
		</dependency>
  • Now, go to LOG4j2.xml file and add following configurations
  • Add application insight package 

 “ packages=“com.microsoft.applicationinsights.log4j.v2″ ” inside the configuration tag.

  • Add the application insight appender and paste your instrumentation key here
<ApplicationInsightsAppender name="aiAppender"
instrumentationKey="your instrumentation key " /> inside
<Appenders> tag
  • Set the log level for application insights
<AsyncLogger name="aiAppender" level="INFO"/>
<AsyncLogger name="aiAppender" level="DEBUG"/>
  • Add application insights Appender which needs to be invoked 
<AppenderRef ref="aiAppender" />
  • Now, run your application and send a request

All the logs are now visible in the application insights

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.