# Streaming MuleSoft Application Logs to Dynatrace with Log4j2

### 1\. Introduction

In today’s API-driven world, observability is critical. While MuleSoft provides rich logging capabilities out of the box, organizations often need centralized log management to monitor performance, detect issues faster, and improve troubleshooting.

**Dynatrace** is a powerful observability platform that offers **log ingestion, monitoring, and AI-powered anomaly detection**. By integrating MuleSoft 4 logs with Dynatrace, we can achieve **end-to-end visibility** of APIs, integrations, and system flows.

This blog will walk through the steps to configure MuleSoft 4 logging with **Log4j2** and send logs directly to **Dynatrace Logs Ingest API**.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1759424241780/1b4d614a-c0eb-4285-8158-db21d41185c4.png align="center")

### 2\. Prerequisites

Before getting started, ensure you have:

* MuleSoft Runtime 4.x
    
* Dynatrace SaaS or Managed instance
    
* An **API Token in Dynatrace** with the scope: `logs.ingest`
    
* Basic knowledge of **Log4j2 configuration**
    

---

### 3\. Why Integrate MuleSoft Logs with Dynatrace?

* ✅ Centralized logging and monitoring
    
* ✅ Real-time troubleshooting with Dynatrace dashboards
    
* ✅ AI-based anomaly detection on MuleSoft flows
    
* ✅ Unified observability across microservices, APIs, and Mule apps
    
* ✅ Faster root cause analysis by correlating logs, traces, and metrics
    

---

### 4\. Creating a Dynatrace API Token

1. Log in to **Dynatrace**
    
2. Navigate to **Apps &gt; Access Token**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1759422949447/c743c357-dc8d-46d0-a149-726dc0cffec2.png align="center")

3. Click on Generate Access Token
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1759423055388/79f573ae-cca0-4545-b51e-2eb60890fd40.png align="center")

4. Name the Token, Slect the expiration date
    
5. Select the **scope** → `ingest logs`
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1759423241774/0cff066a-7c1c-4834-b18c-04056b8a2ffe.png align="center")

5. Copy the generated token → You’ll need it in your Log4j2 config
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1759423456743/5c550d61-4016-434f-bd5a-ed964b2a6cda.png align="center")

### Configuring Log4j2 in MuleSoft

MuleSoft uses **Log4j2** as its logging framework. We can configure a custom **HTTP Appender** to send logs directly to Dynatrace.

Appender for Dyantrace

```xml
        <Http name="DynatraceAppender"
			url="https://qru64311.live.dynatrace.com/api/v2/logs/ingest"
			method="POST">
			<Property name="Authorization">Api-Token XXXXXXXXXXX</Property>
			<Property name="Content-Type">application/json</Property>
			<JsonLayout compact="true" eventEol="true" />
		</Http>
```

AsyncRoot:

```xml
<AppenderRef ref="DynatraceAppender" />
```

Example `log4j2.xml`:

```xml
<?xml version="1.0" encoding="utf-8"?>
<Configuration>

	<!--These are some of the loggers you can enable. There are several more 
		you can find in the documentation. Besides this log4j configuration, you 
		can also use Java VM environment variables to enable other logs like network 
		(-Djavax.net.debug=ssl or all) and Garbage Collector (-XX:+PrintGC). These 
		will be append to the console, so you will see them in the mule_ee.log file. -->

	<Appenders>
		<RollingFile name="file"
			fileName="${sys:mule.home}${sys:file.separator}logs${sys:file.separator}test.log"
			filePattern="${sys:mule.home}${sys:file.separator}logs${sys:file.separator}test-%i.log">
			<PatternLayout
				pattern="%-5p %d [%t] [processor: %X{processorPath}; event: %X{correlationId}] %c: %m%n" />
			<SizeBasedTriggeringPolicy size="10 MB" />
			<DefaultRolloverStrategy max="10" />
		</RollingFile>
		<Http name="DynatraceAppender"
			url="https://qru64311.live.dynatrace.com/api/v2/logs/ingest"
			method="POST">
			<Property name="Authorization">Api-Token XXXXXXXXXXX</Property>
			<Property name="Content-Type">application/json</Property>
			<JsonLayout compact="true" eventEol="true" />
		</Http>
	</Appenders>

	<Loggers>
		<!-- Http Logger shows wire traffic on DEBUG -->
		<!--AsyncLogger name="org.mule.service.http.impl.service.HttpMessageLogger" 
			level="DEBUG"/ -->
		<AsyncLogger name="org.mule.service.http" level="WARN" />
		<AsyncLogger name="org.mule.extension.http" level="WARN" />

		<!-- Mule logger -->
		<AsyncLogger
			name="org.mule.runtime.core.internal.processor.LoggerMessageProcessor"
			level="INFO" />

		<AsyncRoot level="INFO">
			<AppenderRef ref="file" />
			<AppenderRef ref="DynatraceAppender" />
		</AsyncRoot>


	</Loggers>

</Configuration>
```

### Testing the Integration

1. Deploy a MuleSoft application
    
2. Generate logs by sending requests to your Mule APIs
    
3. Go to **Dynatrace &gt; Logs**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1759427127889/df58b95f-fcbc-46bd-a7bd-700174c4a0e6.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1759427146475/2d70876a-f819-403c-bfa9-c8f368799ee3.png align="center")

1. Filter by `source="mule"` or check for your MuleSoft application name
    
2. You should see real-time logs flowing into Dynatrace.
    

---

### Conclusion

By integrating **MuleSoft 4 logs with Dynatrace**, you gain **real-time visibility, centralized observability, and AI-powered insights** into your APIs and integration flows. This setup helps developers and operations teams proactively monitor, detect issues.

With this integration, MuleSoft logs become a **powerful observability signal** in Dynatrace, allowing you to correlate logs with metrics and traces for **full-stack monitoring**.
