Vibhuti
Vibhuti

Reputation: 61

Azure Functions: Configure Slf4j binding with Log4j2 and send logs to appinsights

I am using an Azure Function and I need to perform logging using slf4j binding with log4j2. I want my logs to get stored in application insights (Azure monitor). For this I have a log4j2.xml file for configuration, where I add the ApplicationInsights Appender and set the instrumentation key for the application insights resource.

Currently the behavior is that when I use ExecutionContext.getLogger.info("..."), I see the logs getting stored in app insights, but this uses java.util.logging only. However, when I use the slf4j logger for logging, the logs are not getting stored in app insights, I can only see them on console.

What is the correct way to configure slf4j with log4j2 binding for sending logs to app-insights in Azure Functions? Is that possible, or do azure functions only support java.util.logging library for logging to appinsights?

Upvotes: 3

Views: 1485

Answers (1)

Vibhuti
Vibhuti

Reputation: 61

The default behavior of Azure Functions is to send logs to application insights using the java.util.logging library. The reason I was not seeing slf4j logs in application insights was that I had not excluded other logging libraries from my pom.xml. After adding all exclusions, slf4j-log4j2 combination works fine and I can see the logs in my application insights resource.

Upvotes: 1

Related Questions