---
title: "Policy-based Logging for Azure API Management: Full Payload, Context, and Retention with Nodinite"
description: Discover how Nodinite enables policy-based logging for Azure API Management, providing full payload and context capture, flexible retention, and non-intrusive integration for actionable insights and compliance.
---

# :fa-cloud-arrow-down: Azure API Management Service Policy-based Logging

Unlock comprehensive, policy-based logging for your Azure API Management Service APIs with :Nodinite:. This guide shows you how to capture every request and response—including payloads and headers—without intrusive code changes or data loss.

✅ Capture full payloads and headers for every API request and response  
✅ Eliminate data loss—extract and reindex new fields anytime  
✅ Apply granular retention policies by message type  
✅ Integrate non-intrusively with your existing solutions  
✅ Gain actionable insights and ensure compliance with ease  

>[!INFO]
>This guide teaches you how to apply a :Nodinite:-specific policy to enable logging from the Azure API Management Service platform.

## Why Choose Nodinite Logging Over Application Insights and Competing Solutions?

In today’s fast-paced business environments, you need more than just data collection—you need actionable insights and complete context. While tools like Application Insights and other platforms require predefined logic to capture key values, :Nodinite: Logging removes the guesswork, prevents data loss, and gives you long-term flexibility.

## :fa-rocket: Nodinite Logging vs. Application Insights & Other Competitors

### 1. Full Payload Logging—No Predefined Logic Needed

* With :Nodinite:, you avoid coding up-front logic to extract key values like correlation IDs, order numbers, or transaction details.  
* Log all message payloads and context values in full, ensuring you always have complete visibility.  
* If you forget to log a value with Application Insights or similar tools, it’s lost forever. With :Nodinite:, you can extract and index new fields at any time.  
* :Nodinite: imposes no size restriction, unlike many other options.  

*Key Advantage:* You don’t need developers to anticipate every logging requirement—log everything and extract later as needed.  

### 2. Flexible Search & Reindexing—No More Data Loss

* Competing solutions make it too late to add a new search field after logging.  
* :Nodinite: lets you create new search fields and reindex old data anytime, preserving historical context.  
* If you extract a field incorrectly, just fix the expression and reindex—no data lost.  

*Key Advantage:* You avoid data loss from changing business needs or mistakes in log field definitions.  

### 3. Non-Intrusive, Policy-Based Logging

* Unlike Application Insights, which requires custom logging code, :Nodinite: uses a policy-based, non-intrusive approach.  
* Log in parallel with your existing monitoring solutions—no application changes required.  

*Key Advantage:* Achieve low performance overhead, no intrusive code changes, and full flexibility to run alongside existing tools and policies.  

### 4. Granular, Message-Type Level Retention

* Competing solutions limit retention by fixed days or quotas, forcing you to choose between losing logs or paying more.  
* :Nodinite: lets you define retention per message type, so you keep high-value transactions longer and purge less important logs earlier.  

*Key Advantage:* Optimize retention based on business value, not arbitrary limits or storage constraints.  

## :fa-fire: The Bottom Line: Why Nodinite Wins

✅ Log everything—no upfront coding required  
✅ Prevent data loss—reindex old data anytime  
✅ Log large payloads—no message size limits  
✅ Integrate non-intrusively—run alongside existing solutions  
✅ Control retention—keep critical logs longer without extra cost  

>[!TIP]
>**With :Nodinite:, you never have to say "I wish we had logged that." Everything is available when you need it.**

---

This guide presents three ways to create and send the :Nodinite: [Log Event][].  

|Policy|Full payload ([Body](#body))|HTTP Headers ([Context](#context))|:fa-traffic-light: Monitoring|  
|---|---|---|---|  
|:fa-boxes: 1. Any size, [Blob Storage Policy][] (**recommended**)|✅ Yes|✅ Yes|[Azure Agent][]<br/>[Non Events Agent][]|  
|:fa-code-branch: 2. <200KB, [Event Hub Policy][]|✅ Yes|✅ Yes|[Azure Agent][]<br/>[Non Events Agent][]|  
|:fa-link: 3. Direct API call [Log API Policy][] (supported, but not recommended)|✅ Yes|✅ Yes|[Web Services Agent][]<br/>[Non Events Agent][]|  

<div class="mermaid">
graph LR
    subgraph "Payload (Any size)"
        AA[Azure API Management</br>with Policy 1 - Blob Storage] --> | 1. Log Event | roBS[Blob Storage]  
    end
    subgraph "Payload < 200KB"
        A[Azure API Management</br>with Policy 2 Event Hub]
        A --> | 2. Log Event | B(Event Hub)  
    end
    subgraph "Consumption tier - API Call"
        AAA[Azure API Management</br>with Policy 3]
    end
    subgraph "Nodinite"
        AAA -.->|"3. Log Event (NOT our recommendation)"| F  
        B --> C{Pickup Service}
        C --> F[Log API]
        roBS --> C
    end
</div>

*Diagram: Policy-based logging and event flow for Azure API Management and Nodinite.*

When you activate the policy ([Blob Storage Policy][] or [Event Hub Policy][]), the code running in **Azure API Management** creates a :Nodinite:-specific [JSON Log Event][] and sends it to intermediate storage.

The :Nodinite: [Pickup Log Events Service Logging Agent][] collects the :Nodinite: [Log Events][Log Event] from the intermediate store (Event Hub or Blob Storage Container). This pattern is [Asynchronous][Asynchronous Logging].

>[!TIP]
>:fa-clock: Use the :Nodinite: [Non-Events Monitoring Agent][Non Events Agent] to get alerts if you have too many or too few events within a period.

## Body

Log the full payload. If you use the [Blob Storage Policy][], message size does not matter. If it is <200KB, use the [Event Hub Policy][]. Storing the payload in :Nodinite: lets you use [Search Fields][] in [Log Views][] to create a rich, on-demand user experience for your business.

>[!IMPORTANT]
>When you log the payload, provide a name for the [Message Type][Message Types].

You can change the body display using [Stylesheets][]. This lets you hide content as needed. Use [Role][Roles]-based security to control who can access and view content.

## Context

A :Nodinite: [Log Event][] supports a **Context**—a collection of key-value pairs. Along with HTTP Headers, you can add properties in the Logging policy. Later, use these to create [Search Fields][] for self-service [Log Views][].

<table>
    <tr>
        <th>Request Headers</th>
        <th>Response Headers</th>
    </tr>
    <tr>
        <td><img src="{ndm}/Documentation%20Pictures/LogAgent/AzureAPIMgmt/RequestContext.png" alt="Example of request headers captured in Nodinite logging context"/></td>
        <td><img src="{ndm}/Documentation%20Pictures/LogAgent/AzureAPIMgmt/ResponseContext.png" alt="Example of response headers captured in Nodinite logging context"/></td>
    </tr>
</table>

*Screenshots: Example of request and response headers captured by Nodinite logging.*

>[!TIP]
>You can add to your policy exactly which properties to include in the Logging.

If you log too much, adjust the following [System Parameter][System Parameters]:

* [ContextPropertiesFilters][]

Since you control Logging in the Policy, you determine what to include up front.

---

## Troubleshooting

Contact our [Support][] if you need help implementing [Logging][].

### Logging Options

The diagram below shows the different options for logging from Azure to :Nodinite:.

<div class="mermaid">
graph LR
    subgraph "Integration solution"
        C[Azure Function</br>with Serilog logging] --- | <1 MB payload | C1(Serilog Event Hub Sink)  
        C --> | Any size | C2(Serilog Blob Storage Sink)  
        A[Azure API Management Service API</br>with Policy] --- | <200 KB payload | A2(Policy2)  
        A --- | Any size | A1(Policy1)  
        B[Azure Logic App</br>with the proper diagnostic setting enabled]
    end
    subgraph "Event Hub"
        A2--> | 1. Nodinite JSON Log Event | AA(EH1)  
        C1--> | 1. Nodinite JSON Log Event | AA  
        C1 -.- | 1. Nodinite JSON Log Event | CC(EH2)  
        B--> | 2. Azure Diagnostics log | BB(EH3)  
    end
    subgraph "Azure Storage Account"
        A1--> | 1. Nodinite JSON Log Event | Cont(Container1)  
    end
    C2 --> | 1. Nodinite JSON Log Event | Cont  
    subgraph "Nodinite"
        Cont --> ro[Pickup Service]
        AA --> ro
        CC -.-> ro
        BB --> roLA(Logic Apps Logging and Monitoring Agent)
    end
</div>

*Diagram: Logging options from Azure to Nodinite, including API Management, Functions, and Logic Apps.*

If you log from the API **policy** to an Event Hub entity, you can reuse the Event Hub entity if the content is a :Nodinite: [JSON Log Event][].

>[!IMPORTANT]
>EH1, EH2, and EH3 must each have their own syncpoint (bookmark)—one blob storage container for each event hub entity and client.

* Use the [Blob Storage Policy][] if possible for less administration and large message support.  
* [Logging from Azure functions][Serilog] can share the same Event Hub as APIM if the Log Event is a :Nodinite: [JSON Log Event][].  
* [Logging from Azure Logic Apps][LogicAppsAgent] requires other event hubs as targets since the content is in a different format.  

>[!TIP]
>Use separate event hub entities for different purposes and needs—multiple Logic App Logging, multiple API Management Services, multiple APIs, multiple Azure functions, all according to your architecture.

Using a shared Event Hub for a :Nodinite: [JSON Log Event][] reduces administration (configure the :Nodinite: [Pickup Log Events Service Logging Agent][] to fetch these events).<br/>The disadvantage can be performance-related, or you may need to consider pricing, scalability, retention, and number of partitions.

>[!IMPORTANT]
>Do not use the same Event Hub Entity for [Logic Apps Logging][LogicAppsAgent] as for [Serilog][] and Policy-based solutions. Diagnostics from Logic Apps are from Microsoft, while the others create a :Nodinite: [JSON Log Event]. These cannot appear on the same Event Hub Entity.

## :fa-shield-check: What firewall settings are required for Azure API Management logging?

Azure API Management opens every connection **outbound**; no :Nodinite: agent runs in Azure, and there is no [Monitoring Service][] or Agent Server hop for logging. The policy decides the path: the [Blob Storage Policy][] and the [Event Hub Policy][] write to intermediate storage that the :Nodinite: [Pickup Service][Pickup Log Events Service Logging Agent] reads, and the [Log API Policy][] posts directly to the :Nodinite: [Log API][]. Each arrow starts at the side that opens the connection.

<div class="mermaid">
graph LR
    subgraph "Azure API Management"
        roAPIM(fa:fa-cloud API with Nodinite policy)
    end
    subgraph "Azure Storage"
        roBlob(fa:fa-boxes *.blob.core.windows.net)
    end
    subgraph "Azure Event Hubs"
        roEH(fa:fa-code-branch *.servicebus.windows.net)
    end
    subgraph "Nodinite Core Services Server"
        roPickup(fa:fa-truck-pickup Pickup Service)
        roLogAPI(fa:fa-cloud-arrow-down Log API)
    end
    roAPIM --> |"443"| roBlob
    roAPIM --> |"5671-5672, 443"| roEH
    roAPIM -.-> |"Log API site port"| roLogAPI
    roPickup --> |"see Pickup Service"| roBlob
    roPickup --> |"see Pickup Service"| roEH
</div>

*Network diagram: APIM writes to Blob Storage or Event Hubs, and the Pickup Service collects the Log Events. The dashed direct Log API call is supported but not recommended.*

### Between Azure API Management and Azure Storage or Event Hubs

These rules matter only when you restrict APIM outbound traffic (VNet injection with a network security group or a firewall). See the Microsoft [virtual network configuration reference](https://learn.microsoft.com/en-us/azure/api-management/virtual-network-reference)<sup>:fa-arrow-up-right-from-square:</sup>. For Storage Accounts and Event Hubs behind their own firewall, see [Network Restrictions & Alternative Solutions][Network Restrictions].

|Direction|Source|Destination|Protocol|Port(s)|Purpose|Notes|  
|---|---|---|---|---|---|---|  
|Outbound|Azure API Management|`<account>.blob.core.windows.net`|TCP|443|HTTPS|[Blob Storage Policy][]|  
|Outbound|Azure API Management|`<namespace>.servicebus.windows.net`|TCP|5671, 5672, 443|AMQP, HTTPS|[Event Hub Policy][]; service tag `EventHub`|  

### Between Azure API Management and the Log API

Required only for the [Log API Policy][]. On Windows Server, :Nodinite: v7 hosts the [Log API][] as its own [IIS][] web site, on a port you set per environment in the :Nodinite: Portal ([Servers step][]).

|Direction|Source|Destination|Protocol|Port(s)|Purpose|Notes|  
|---|---|---|---|---|---|---|  
|Inbound|Azure API Management|Core Services Server|TCP (HTTPS)|Log API site port|Post Log Events|Allow the APIM outbound IP addresses, or reach the Log API through your VNet|  

### Between the Pickup Service and Azure Storage or Event Hubs

The [Pickup Service][Pickup Log Events Service Logging Agent] reads the container or Event Hub and posts to the Log API; see the [Pickup Service firewall settings][Pickup firewall].

### Between the servers and DNS

|Direction|Source|Destination|Protocol|Port(s)|Purpose|Notes|  
|---|---|---|---|---|---|---|  
|Outbound|Azure API Management|DNS Server|TCP/UDP|53|Name resolution|Only with custom DNS in a VNet; Azure DNS needs no rule|  

>[!IMPORTANT]
>**Stateful Firewalls**: Response traffic for established outbound connections is allowed automatically.

## :fa-hand-point-right: Next Steps

:fa-truck-pickup: [Pickup Log Events Service Logging Agent][]  
:fa-user-secret: [Azure Application Access][AzureApplicationsAccess]  

## :fa-link-horizontal: Related Topics

:fa-file-code: [JSON Log Event][]  
:fa-wrench: [Managing][Azure Agent - Managing API Logger]  
:fa-monitor-waveform: [Monitoring][Azure Agent - Monitoring Logger]  
:fa-clock: [Non Events Agent][]  
:fa-file-lines: [Stylesheets][]  
:fa-coins: [Reduce Azure API Management Logging Costs][]  

Interested in logging from other Azure Related Services?

* [Logging from Azure Logic Apps][LogicAppsAgent]  
* [Logging from Azure functions][Serilog]  

[Asynchronous Logging]:{ndr}/Core%20Services/Log%20API/Features/Asynchronous%20Logging.md
[Azure Agent]:{ndr}/Logging%20and%20Monitoring/Azure/Overview.md
[Azure Agent - Managing API Logger]:{ndr}/Logging%20and%20Monitoring/Azure/Features/API%20Management/Event%20Hub%20Logger/Managing%20Logger.md
[Azure Agent - Monitoring Logger]:{ndr}/Logging%20and%20Monitoring/Azure/Features/API%20Management/Event%20Hub%20Logger/Monitoring%20Logger.md
[AzureApplicationsAccess]:{ndr}/Install%20and%20Update/Troubleshooting/Azure/Azure%20Application%20Access.md
[Blob Storage Policy]:{ndr}/Logging%20and%20Monitoring/Azure%20API%20Management/Policy/Blob%20Storage.md
[ContextPropertiesFilters]:{ndr}/Administration/5.%20Settings/5.%20System%20Parameters/ContextPropertiesFilters.md
[Event Hub Policy]:{ndr}/Logging%20and%20Monitoring/Azure%20API%20Management/Policy/Event%20Hub.md
[IIS]:{ndr}/Install%20and%20Update/Troubleshooting/IIS/Overview.md
[JSON Log Event]:{ndr}/Core%20Services/Log%20Event/Features/JSON%20Log%20Event.md
[Log API]:{ndr}/Core%20Services/Log%20API/Overview.md
[Log API Policy]:{ndr}/Logging%20and%20Monitoring/Azure%20API%20Management/Policy/Log%20API.md
[Log Event]:{ndr}/Core%20Services/Log%20Event/Overview.md
[Log Views]:{ndr}/Administration/1.%20Log%20Management/1.%20Log%20Views/Features/What%20is%20a%20Log%20View.md
[Logging]:nodiniteDoc:/Logging
[LogicAppsAgent]:{ndr}/Logging%20and%20Monitoring/Azure%20Logic%20Apps/Overview.md
[Message Types]:{ndr}/Repository%20Model/Message%20Types/Overview.md
[Monitoring Service]:{ndr}/Core%20Services/Monitoring%20Service/Overview.md
[Network Restrictions]:{ndr}/Logging%20and%20Monitoring/Azure%20API%20Management/Policy/Network%20Restrictions.md
[Non Events Agent]:{ndr}/Logging%20and%20Monitoring/Non-Events/Overview.md
[Pickup firewall]:{ndr}/Logging%20and%20Monitoring/Pickup%20LogEvents%20Service/Getting%20started/1.%20Prerequisites.md#fa-shield-check-firewall-requirements
[Pickup Log Events Service Logging Agent]:{ndr}/Logging%20and%20Monitoring/Pickup%20LogEvents%20Service/Overview.md
[Reduce Azure API Management Logging Costs]:{ndr}/Logging%20and%20Monitoring/Azure%20API%20Management/Troubleshooting/Reduce%20Azure%20API%20Management%20Logging%20Costs.md
[Roles]:{ndr}/Administration/3.%20Access%20Management/1.%20Roles/Features/What%20is%20a%20Role.md
[Search Fields]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/What%20is%20a%20Search%20Field.md
[Serilog]:{ndr}/Logging%20and%20Monitoring/Serilog/Overview.md
[Servers step]:{ndr}/Install%20and%20Update/Getting%20started/Version%207/Install%20Nodinite%20v7%20Steps/04%20-%20Servers.md#core-platform-services
[Stylesheets]:{ndr}/Administration/4.%20Customize/2.%20Stylesheets/Features/What%20is%20a%20Stylesheet.md
[Support]:https://support.nodinite.com
[System Parameters]:{ndr}/Administration/5.%20Settings/5.%20System%20Parameters/Overview.md
[Web Services Agent]:{ndr}/Logging%20and%20Monitoring/Web%20Services/Overview.md