---
title: Blob Storage Policy-based Logging for Azure API Management Service APIs with Nodinite
description: Learn how to implement Blob Storage Policy-based Logging for Azure API Management Service APIs with Nodinite. Track all requests and responses, including payloads and headers, and enable robust monitoring and alerting.
---

# Blob Storage Policy

<aside aria-label="Important" class="nodinite-note nodinite-note--important">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-message-exclamation"></i> Important</p>
<div class="nodinite-note__content"><p><strong>Azure Trusted Service Connectivity Retirement (March 2026)</strong> - Microsoft is retiring the Trusted Services feature, which affects logging from APIM to Azure Blob Storage when network restrictions are enabled. Read the <a href="https://learn.microsoft.com/en-us/azure/api-management/breaking-changes/trusted-service-connectivity-retirement-march-2026">Microsoft announcement</a><sup><i class="fal fa-arrow-up-right-from-square" aria-hidden="true"></i></sup> and review the <a href="https://docs.nodinite.com/logging-and-monitoring/azure-api-management/policy/network-restrictions/">alternative solutions</a>.</p></div>
</aside>

<aside aria-label="Info" class="nodinite-note nodinite-note--info">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-square-info"></i> Info</p>
<div class="nodinite-note__content"><p>This guide explains how to apply a <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span>-specific policy that enables comprehensive logging from the Azure API Management platform to <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span>.</p></div>
</aside>

✅ Track all API requests and responses, including payloads and headers, with ease  
✅ Achieve [asynchronous][Asynchronous Logging], scalable logging for any payload size  
✅ Monitor and receive real-time alerts with <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> agents  
✅ Maintain compliance and traceability through end-to-end logging  

The diagram below shows the end-to-end flow for logging events from Azure API Management to Blob Storage and then to <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span>.

<div class="mermaid">
graph LR
    subgraph "Payload (Any size)"
        AA[Azure API Management</br>with Policy 2] --> | 1. Log Event, </br>Any size | roBS[Blob Storage]  
    end
    subgraph "Nodinite"
        roBS --> C{Pickup Service}
        C --> F[Log API]
    end
</div>

*Diagram: End-to-end flow for logging API events from Azure API Management to Blob Storage and <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span>.*

When you activate the **Blob Storage Policy**, the code running in the **Azure API Management** platform generates a <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span>-specific [JSON Log Event][] and stores it in the Blob Storage Container. This approach captures every request and response, regardless of payload size, and ensures all relevant data remains available for monitoring and analysis.

<aside aria-label="Tip" class="nodinite-note nodinite-note--tip">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-lightbulb"></i> Tip</p>
<div class="nodinite-note__content"><p>Use the <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> <a href="https://docs.nodinite.com/logging-and-monitoring/azure/overview/">Azure Monitoring Agent</a> to receive alerts if <a href="https://docs.nodinite.com/core-services/log-event/overview/">Log Events</a> accumulate in Blob Storage. The <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> <a href="https://docs.nodinite.com/logging-and-monitoring/pickup-logevents-service/overview/">Pickup Log Events Service Logging Agent</a> consumes these <a href="https://docs.nodinite.com/core-services/log-event/overview/">Log Events</a>. You can also configure a backout container for malformed messages, ensuring you do not lose data and that all issues are monitored.</p></div>
</aside>

The <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> [Pickup Log Events Service Logging Agent][] processes [Log Events][Log Event] from Blob Storage asynchronously, providing scalable and reliable logging.

<aside aria-label="Tip" class="nodinite-note nodinite-note--tip">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-lightbulb"></i> Tip</p>
<div class="nodinite-note__content"><p>The <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> <a href="https://docs.nodinite.com/logging-and-monitoring/non-events/overview/">Non-Events Monitoring Agent</a> alerts you if the number of events deviates from expectations, helping you maintain operational integrity.</p></div>
</aside>

## Configuration Steps

Follow these steps to enable logging to <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> in your Azure API Management Service APIs:

* <i class="fal fa-user-gear" aria-hidden="true"></i> Add and configure a [Managed Identity](#fa-user-gear-managed-identity)  
* Add and configure [Named Values](#named-values)  
* Add [Policy Fragments](#policy-fragments)  
  * [Inbound Policy Fragment](#inbound-policy-fragment)
  * [Outbound Policy Fragment](#outbound-policy-fragment)
  * [On-Error Policy Fragment](#on-error-policy-fragment)
* [Add a reference to Policy Fragments in **All APIs**](#add-a-reference-to-policy-fragments-in-all-apis)
  * [Inbound Processing](#inbound-processing)
    * [Inbound Policy Fragment](#inbound-policy-fragment-inbound-processing)
  * [Outbound Processing](#outbound-processing)
    * [Outbound Policy Fragment](#outbound-policy-fragment-outbound-processing)
  * [On-Error Processing](#on-error)
* [Variables](#variables)
  * [Set variable on **All operations**](#set-variable-on-all-operations)
  * [Set variables on the API level (inbound)](#set-variables-on-the-api-level-inbound)
  * [Set variables on the API level (outbound)](#set-variables-on-the-api-level-outbound)
  * [Set variables on the API level (on-error)](#set-variables-on-the-api-level-on-error)

Next, configure the <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> [Pickup Log Events Service Logging Agent][] to consume [Log Events][Log Event] from Blob Storage. Route malformed [Log Events][Log Event] to a backout container for further analysis.

Configure the <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> [Azure Monitoring Agent][Azure Agent] to ensure you do not stockpile [Log Events][Log Event] in your destination or backout containers.

Create and use <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> [Log Views][] with [Search Fields][] to provide business users and stakeholders with actionable insights into your logged data.

Optionally, set up the <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> [Non-Events Monitoring Agent][Non Events Agent] to validate that you receive the expected number of [Log Events][Log Event] during a given period.

____

## <i class="fal fa-user-gear" aria-hidden="true"></i> Managed Identity

In the **Blob Storage Policy**, you use a user-assigned [Managed Identity](https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/overview)<sup><i class="fal fa-arrow-up-right-from-square" aria-hidden="true"></i></sup> to securely access Azure resources.

1. Create (or reuse) a Managed Identity in the [Azure Portal](https://portal.azure.com)<sup><i class="fal fa-arrow-up-right-from-square" aria-hidden="true"></i></sup>.  
2. Note the Client ID; you will need it in the [Named Values](#named-values) section.  
  ![Managed Identity Client ID][1]  
   *Image: Managed Identity Client ID in Azure Portal.*  
3. Assign the **Storage Blob Contributor** role to the Managed Identity on the Storage Account referenced by the `logging-blob-url` named value.  
  ![Manage Identity - Storage Account][2]  
   *Image: Assigning Storage Blob Contributor role to Managed Identity.*  
4. Add the Managed Identity to the API Management Service where you will apply the **Blob Storage Policy**.  
  ![Managed Identity - APIM][7]  
   *Image: Adding Managed Identity to API Management Service.*

## Named Values

The **Blob Storage Policy** uses variables to avoid hard-coding values. You can expand the sample with additional properties as your business and policy require.

In the [Azure Portal](https://portal.azure.com)<sup><i class="fal fa-arrow-up-right-from-square" aria-hidden="true"></i></sup>, navigate to the API Management Service and click **Named Values** in the sidebar.  
![Named Values][3]  
   *Image: Named Values configuration in Azure Portal.*  

Create the following named values:

1. `logging-blob-mid-client-id` – Enter the Client ID of the Managed Identity from the previous [step](#fa-user-gear-managed-identity).
2. `logging-blob-url` – Enter the URL for the Blob Storage Container. Ensure the value ends with a trailing slash (`/`). You can omit the trailing slash if you also change the code in the sample.  
  ![Blob Storage Container URL][4]  
   *Image: Blob Storage Container URL example.*  

## Policy Fragments

The **Blob Storage Policy** uses three Policy Fragments:

1. Inbound Policy Fragment – Creates a <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> [JSON Log Event][] for **Inbound Processing**.
2. Outbound Policy Fragment – Creates a <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> [JSON Log Event][] for **Outbound Processing**.
3. On Error Policy Fragment – Creates a <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> [JSON Log Event][] when an error occurs in **Inbound** or **Outbound Processing**.

<aside aria-label="Tip" class="nodinite-note nodinite-note--tip">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-lightbulb"></i> Tip</p>
<div class="nodinite-note__content"><p>All events in the sample use the <code>x-ms-client-tracking-id</code> header value. This ID enables end-to-end logging and is vital for all <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> <a href="https://docs.nodinite.com/core-services/log-event/overview/">Log Events</a>. You can group all <a href="https://docs.nodinite.com/core-services/log-event/overview/">Log Events</a> for an interchange in a <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> <a href="https://docs.nodinite.com/administration/log-management/log-views/features/what-is-a-log-view/">Log View</a> by the built-in <a href="https://docs.nodinite.com/administration/log-management/search-fields/features/what-is-a-search-field/">Search Field</a> <code>Application interchange id</code>. If you call an Azure Function using the <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> <a href="https://docs.nodinite.com/logging-and-monitoring/serilog/overview/">Serilog</a> sinks, add this header to the context to retain the value through the whole chain of events. If you invoke a Logic App, the system handles this automatically.<br>
<img src="https://docs.nodinite.com/media/Documentation%20Pictures/LogAgent/AzureAPIMgmt/Blob/GroupByApplicationInterchangeID.png" alt="Group by Application interchange id" class="nodinite-zoom"><br>
<em>Image: Grouping by Application interchange id in Nodinite Log View.</em></p></div>
</aside>

### Inbound Policy Fragment

1. In the [Azure Portal](https://portal.azure.com)<sup><i class="fal fa-arrow-up-right-from-square" aria-hidden="true"></i></sup>, navigate to the API Management Service, then, in the sidebar, click **Policy Fragments**.
2. Create a new Policy Fragment and name it, for example, `InboundLoggingPolicyFragment`.  
  ![Policy Editor - Inbound Policy Fragment][6]  

|Property|Value|Comment|  
|---|---|---|  
|<i class="fal fa-box-archive" aria-hidden="true"></i> [LogAgentValueId][Log Agents]|3|Once set, you should NOT change this value. Ensure it is not already in use before you start to log.|  
|<i class="fal fa-diamond-turn-right" aria-hidden="true"></i> [EndPointDirection][Endpoint Directions]|10|Two-way Receive|  
|<i class="fal fa-plug" aria-hidden="true"></i> [EndPointTypeId][EndpointTypes]|71|Microsoft Azure API Management|  
|<i class="fal fa-arrows-left-right" aria-hidden="true"></i> [EventDirection][EventDirections]|21|ExternalIncomingRequest|  

*The fields are all part of a <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> [Log Event][].*

```xml
<fragment>
    <!-- Start Logging -->
    <set-header name="x-ms-client-tracking-id" exists-action="skip">
        <value>@(Guid.NewGuid().ToString())</value>
    </set-header>
    <set-variable name="correlationId" value="@{
            return context.Request.Headers.GetValueOrDefault("x-ms-client-tracking-id");
        }" />
    <send-request mode="new" timeout="20" response-variable-name="blobdata" ignore-error="true">
        <set-url>@($"{{logging-blob-url}}{Guid.NewGuid().ToString()}.json")</set-url>
        <set-method>PUT</set-method>
        <set-header name="x-ms-version" exists-action="override">
            <value>2019-07-07</value>
        </set-header>
        <set-header name="x-ms-blob-type" exists-action="override">
            <value>BlockBlob</value>
        </set-header>
        <set-body>@{
            var body = context.Request?.Body?.As<string>(preserveContent: true) ?? "";
            var bodyToLog = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(body));

            var headers = context.Request.Headers.Where(h => !h.Key.Equals("authorization", StringComparison.InvariantCultureIgnoreCase) && !h.Key.Equals("ocp-apim-subscription-key", StringComparison.InvariantCultureIgnoreCase));
            var correlationId = context.Variables.GetValueOrDefault<string>("correlationId");

            Dictionary<string, string> contextProperties = new Dictionary<string, string>();
            contextProperties.Add("CorrelationId", correlationId);
        
            foreach (var h in headers) {
                contextProperties.Add(string.Format("Header#{0}", h.Key), String.Join(", ", h.Value));
            }
            
            var requestLogMessage = new {
                LogAgentValueId = 3,
                EndPointName = context.Api.Name + "/" + context.Operation.Name,
                EndPointUri = context.Deployment.ServiceName + "/" + context.Api.Name + "/" + context.Operation.Name,
                EndPointDirection = 10,
                EndPointTypeId = 71,
                EventDirection = 21,
                OriginalMessageTypeName = context.Variables.GetValueOrDefault<string>("loggingSchemaRoot", "UndeclaredSchemaRoot") + "#" + context.Variables.GetValueOrDefault<string>("loggingSchemaName", "UndeclaredSchemaName"),
                LogDateTime = DateTime.UtcNow,
                ApplicationInterchangeId = correlationId,
                Context = contextProperties,
                LogText = context.Variables.GetValueOrDefault<string>("logtext", ""),
                Body = bodyToLog
            };

            return JsonConvert.SerializeObject(requestLogMessage);
            }</set-body>
        <authentication-managed-identity client-id="{{logging-blob-mid-client-id}}" resource="https://storage.azure.com" />
    </send-request>
    <!-- End Logging -->
</fragment>
```

### Outbound Policy Fragment

|Property|Value|Comment|  
|---|---|---|  
|<i class="fal fa-box-archive" aria-hidden="true"></i> [LogAgentValueId][Log Agents]|3|Once set, you should NOT change this value. Ensure it is not already in use before you start to log.|  
|<i class="fal fa-diamond-turn-right" aria-hidden="true"></i> [EndPointDirection][Endpoint Directions]|10|Two-way Receive|  
|<i class="fal fa-plug" aria-hidden="true"></i> [EndPointTypeId][EndpointTypes]|71|Microsoft Azure API Management|  
|<i class="fal fa-arrows-left-right" aria-hidden="true"></i> [EventDirection][EventDirections]|25|ExternalIncomingResponse|  

```xml
<fragment>
    <!-- Start Logging -->
    <set-header name="x-ms-client-tracking-id" exists-action="skip">
        <value>@(Guid.NewGuid().ToString())</value>
    </set-header>
    <set-variable name="correlationId" value="@{
            return context.Response.Headers.GetValueOrDefault("x-ms-client-tracking-id");
        }" />
    <send-request mode="new" timeout="20" response-variable-name="blobdata" ignore-error="true">
        <set-url>@($"{{logging-blob-url}}{Guid.NewGuid().ToString()}.json")</set-url>
        <set-method>PUT</set-method>
        <set-header name="x-ms-version" exists-action="override">
            <value>2019-07-07</value>
        </set-header>
        <set-header name="x-ms-blob-type" exists-action="override">
            <value>BlockBlob</value>
        </set-header>
        <set-body>@{
            var body = context.Response?.Body?.As<string>(preserveContent: true) ?? "";
            var bodyToLog = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(body));

            var headers = context.Response.Headers.Where(h => !h.Key.Equals("authorization", StringComparison.InvariantCultureIgnoreCase) && !h.Key.Equals("ocp-apim-subscription-key", StringComparison.InvariantCultureIgnoreCase));
            var correlationId = context.Variables.GetValueOrDefault<string>("correlationId");

            Dictionary<string, string> contextProperties = new Dictionary<string, string>();
            contextProperties.Add("CorrelationId", correlationId);
        
            foreach (var h in headers) {
                contextProperties.Add(string.Format("Header#{0}", h.Key), String.Join(", ", h.Value));
            }
            
            var requestLogMessage = new {
                LogAgentValueId = 3,
                EndPointName = context.Api.Name + "/" + context.Operation.Name,
                EndPointUri = context.Deployment.ServiceName + "/" + context.Api.Name + "/" + context.Operation.Name,
                EndPointDirection = 10,
                EndPointTypeId = 71,
                EventDirection = 25,
                OriginalMessageTypeName = context.Variables.GetValueOrDefault<string>("loggingSchemaRoot", "UndeclaredSchemaRoot") + "#" + context.Variables.GetValueOrDefault<string>("loggingSchemaName", "UndeclaredSchemaName"),
                LogDateTime = DateTime.UtcNow,
                ApplicationInterchangeId = correlationId,
                Context = contextProperties,
                LogText = context.Variables.GetValueOrDefault<string>("logtext", ""),
                Body = bodyToLog
            };

            return JsonConvert.SerializeObject(requestLogMessage);
            }</set-body>
        <authentication-managed-identity client-id="{{logging-blob-mid-client-id}}" resource="https://storage.azure.com" />
    </send-request>
    <!-- End Logging -->
</fragment>
```

### On-Error Policy Fragment

<aside aria-label="Note" class="nodinite-note nodinite-note--note">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-note"></i> Note</p>
<div class="nodinite-note__content"><p>The <a href="https://docs.nodinite.com/administration/log-management/log-agents/features/what-is-a-log-status-code/">LogStatus</a> is set to <code>-1</code> to indicate an Error condition.</p></div>
</aside>

```xml
<fragment>
    <!-- Start Logging -->
    <set-header name="x-ms-client-tracking-id" exists-action="skip">
        <value>@(Guid.NewGuid().ToString())</value>
    </set-header>
    <set-variable name="correlationId" value="@{
            return context.Request.Headers.GetValueOrDefault("x-ms-client-tracking-id");
        }" />
    <send-request mode="new" timeout="20" response-variable-name="blobdata" ignore-error="true">
        <set-url>@($"{{logging-blob-url}}{Guid.NewGuid().ToString()}.json")</set-url>
        <set-method>PUT</set-method>
        <set-header name="x-ms-version" exists-action="override">
            <value>2019-07-07</value>
        </set-header>
        <set-header name="x-ms-blob-type" exists-action="override">
            <value>BlockBlob</value>
        </set-header>
        <set-body>@{
            var body = context.Request?.Body?.As<string>(preserveContent: true) ?? "";
            var bodyToLog = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(body));

            var headers = context.Request.Headers.Where(h => !h.Key.Equals("authorization", StringComparison.InvariantCultureIgnoreCase) && !h.Key.Equals("ocp-apim-subscription-key", StringComparison.InvariantCultureIgnoreCase));
            var correlationId = context.Variables.GetValueOrDefault<string>("correlationId");

            Dictionary<string, string> contextProperties = new Dictionary<string, string>();
            contextProperties.Add("CorrelationId", correlationId);
        
            foreach (var h in headers) {
                contextProperties.Add(string.Format("Header#{0}", h.Key), String.Join(", ", h.Value));
            }
            
            var requestLogMessage = new {
                LogAgentValueId = 3,
                EndPointName = context.Api.Name + "/" + context.Operation.Name,
                EndPointUri = context.Deployment.ServiceName + "/" + context.Api.Name + "/" + context.Operation.Name,
                EndPointDirection = 10,
                EndPointTypeId = 71,
                EventDirection = 25,
                OriginalMessageTypeName = context.Variables.GetValueOrDefault<string>("loggingSchemaRoot", "UndeclaredSchemaRoot") + "#" + context.Variables.GetValueOrDefault<string>("loggingSchemaName", "UndeclaredSchemaName"),
                LogDateTime = DateTime.UtcNow,
                ApplicationInterchangeId = correlationId,
                Context = contextProperties,
                LogText = context.Variables.GetValueOrDefault<string>("logtext", ""),
                Body = bodyToLog,
                LogStatus = -1
            };

            return JsonConvert.SerializeObject(requestLogMessage);
            }</set-body>
        <authentication-managed-identity client-id="{{logging-blob-mid-client-id}}" resource="https://storage.azure.com" />
    </send-request>
    <!-- End Logging -->
</fragment>
```

## Add a reference to Policy Fragments in All APIs

In the [Azure Portal](https://portal.azure.com)<sup><i class="fal fa-arrow-up-right-from-square" aria-hidden="true"></i></sup>, navigate to the API Management Service, then, in the sidebar, click **APIs**, then **All APIs**.  
![All APIs][8]  

### Inbound Processing

Use the [Inbound Policy Fragment](#inbound-policy-fragment) to create <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> [Log Events][Log Event] for the **Request**.

#### Inbound Policy Fragment (Inbound Processing)

1. Click on the **Add policy** button.  
    ![Inbound Policy Fragment (Inbound Processing)][9]  
2. Add a reference to the [Inbound Policy Fragment](#inbound-policy-fragment).

```xml
 <inbound>
    <include-fragment fragment-id="InboundLoggingPolicyFragment" />
</inbound>
```

### Outbound Processing

Use the [Outbound Policy Fragment](#outbound-policy-fragment) to create <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> [Log Events][Log Event] for the **Response**.

#### Outbound Policy Fragment (Outbound Processing)

1. Click on the **Add policy** button.  
    ![Outbound Policy Fragment (Outbound Processing)][12]  
2. Add a reference to the [Outbound Policy Fragment](#outbound-policy-fragment).

```xml
<outbound>
    <include-fragment fragment-id="outboundLoggingPolicyFragment" />
</outbound>
```

### On Error

Use the [On-Error Policy Fragment](#on-error-policy-fragment) to create <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> [Log Events][Log Event] when there is an **error**.

```xml
<on-error>
    <include-fragment fragment-id="onerrorLoggingPolicyFragment" />
</on-error>
```

### Complete example with all Policy Fragments

```xml
<policies>
    <inbound>
        <include-fragment fragment-id="InboundLoggingPolicyFragment" />
    </inbound>
    <backend>
        <forward-request />
    </backend>
    <outbound>
        <include-fragment fragment-id="outboundLoggingPolicyFragment" />
    </outbound>
    <on-error>
        <include-fragment fragment-id="onerrorLoggingPolicyFragment" />
    </on-error>
</policies>
```

## Variables

In the final steps with the **Blob Storage Policy**, you need to set a few values. These are commonly used to attribute the <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> [JSON Log Event]. You can develop additional dynamics based on the provided examples.

* [Set variable on **All operations**](#set-variable-on-all-operations)
* [Set variables on the API level (inbound)](#set-variables-on-the-api-level-inbound)
* [Set variables on the API level (outbound)](#set-variables-on-the-api-level-outbound)
* [Set variables on the API level (on-error)](#set-variables-on-the-api-level-on-error)

The following variables are part of the default <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> **Blob Storage Policy**:

|Variable|Default Value|Example|Comment|  
|---|---|---|---|  
|<i class="fal fa-tags" aria-hidden="true"></i> `loggingSchemaRoot`|`UndeclaredSchemaRoot`|`Nodinite.Logging.Schemas`|The **prefix** part of the [Message Type][Message Types] name|  
|<i class="fal fa-tags" aria-hidden="true"></i> `loggingSchemaName`|`UndeclaredSchemaName`|`Orders`|The **suffix** part of the [Message Type][Message Types] name. Should be set on individual operation level|  
|<i class="fal fa-align-left" aria-hidden="true"></i> `logtext`|``|`Hello World`|Empty by default; Can be set on individual operation level|  

<aside aria-label="Info" class="nodinite-note nodinite-note--info">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-square-info"></i> Info</p>
<div class="nodinite-note__content"><p>Using the example values, the name of the <a href="https://docs.nodinite.com/repository-model/message-types/overview/">Message Type</a> in the resulting <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> <a href="https://docs.nodinite.com/core-services/log-event/features/json-log-event/">JSON Log Event</a> is <code>Nodinite.Logging.Schemas#Orders</code>. If possible, please use a <strong>versioning scheme</strong> in real-world scenarios, i.e. <code>Nodinite.Logging.Schemas/1.0#Orders</code></p></div>
</aside>

In the [On-Error](#on-error-policy-fragment), the `LogStatus` is set to -1 (indicating an Error), this is a candidate you may be interested in setting as a variable. Feel free to modify the default Policy Fragments to fit your use case.

* [Log Status Codes][]

### Set variable on **All operations**

In the [Azure Portal](https://portal.azure.com)<sup><i class="fal fa-arrow-up-right-from-square" aria-hidden="true"></i></sup>, navigate to the API Management Service. In the sidebar, click **APIs**, and then select one of the APIs, then **All operations**.  
![Set variable on All operations][10]

#### Complete example

Below is an example of setting the value for `loggingSchemaRoot` for all operations (inbound, outbound, and on-error). You can override the value if you want to on the operation level.

```xml
<policies>
    <!-- Throttle, authorize, validate, cache, or transform the requests -->
    <inbound>
        <set-variable name="loggingSchemaRoot" value="Nodinite.Logging.Schemas" />
        <base />
    </inbound>
    <!-- Control if and how the requests are forwarded to services  -->
    <backend>
        <base />
    </backend>
    <!-- Customize the responses -->
    <outbound>
        <set-variable name="loggingSchemaRoot" value="Nodinite.Logging.Schemas" />
        <base />
    </outbound>
    <!-- Handle exceptions and customize error responses  -->
    <on-error>
        <set-variable name="loggingSchemaRoot" value="Nodinite.Logging.Schemas" />
        <base />
    </on-error>
</policies>
```

### Set variables on the API level (inbound)

For a specific operation, for example, a `POST`, in the **inbound** processing step, you can set the **suffix** part of the [Message Type][Message Types] name as described in the [Variables](#variables) heading. Also, you can set a Log Text (a description field for the <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> [Log Event][])

```xml
 <inbound>
    <set-variable name="loggingSchemaName" value="Orders" />
    <set-variable name="logtext" value="Post OK" />
    <base />
    <set-backend-service id="apim-generated-policy" backend-id="nodinitefunctionapps" />
</inbound>
```

![Operation level - Inbound processing][11]  

### Set variables on the API level (outbound)

In the outbound processing step, we now make changes to the variables. You should set these values according to your business case and match the data in orbit.

```xml
 <outbound>
    <set-variable name="loggingSchemaName" value="OrderResponse" />
    <set-variable name="logtext" value="Response OK" />
    <base />
</outbound>
```

### Set variables on the API level (on-error)

In the on-error processing step, we again make changes to the variables. You should set these values according to your business case and match the data in orbit.

```xml
 <on-error>
    <set-variable name="loggingSchemaName" value="Error" />
    <set-variable name="logtext" value="Error in processing" />
    <base />
</on-error>
```

____

## Redacting Sensitive Data

<aside aria-label="Important" class="nodinite-note nodinite-note--important">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-message-exclamation"></i> Important</p>
<div class="nodinite-note__content"><p><strong>Protect sensitive information in your logs</strong> - By default, the policy examples exclude <code>Authorization</code> and <code>Ocp-Apim-Subscription-Key</code> headers to prevent logging credentials. Review your headers and request/response bodies to ensure no PII (Personally Identifiable Information), secrets, passwords, or API keys are logged.</p></div>
</aside>

### Best Practices

* <i class="fal fa-filter" aria-hidden="true"></i> **Filter headers**: Exclude headers containing sensitive data (authentication tokens, API keys, secrets)
* <i class="fal fa-eraser" aria-hidden="true"></i> **Redact body content**: Hash or remove PII fields from request/response bodies before logging
* <i class="fal fa-list-check" aria-hidden="true"></i> **Use allowlists**: Log only known-safe headers instead of denylisting sensitive ones
* <i class="fal fa-clipboard-check" aria-hidden="true"></i> **Audit regularly**: Review logged data to ensure compliance with data protection regulations

#### Example Header Filtering

```csharp
var headers = context.Request.Headers
    .Where(h => !h.Key.Equals("authorization", StringComparison.InvariantCultureIgnoreCase) 
             && !h.Key.Equals("ocp-apim-subscription-key", StringComparison.InvariantCultureIgnoreCase));
```

<aside aria-label="Tip" class="nodinite-note nodinite-note--tip">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-lightbulb"></i> Tip</p>
<div class="nodinite-note__content"><p>APIM adds diagnostic headers such as <code>Ocp-Apim-Trace-AuthorizationExpired</code> to responses. These are captured by <code>context.Response.Headers</code> in the outbound section and will appear as context properties in <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> logs. See <a href="https://docs.nodinite.com/logging-and-monitoring/azure-api-management/troubleshooting/overview/">APIM Troubleshooting</a> if you want to understand or suppress them.</p></div>
</aside>

For advanced redaction techniques, custom body filtering, and security hardening options, see [Network Restrictions & Alternative Solutions - Redact Sensitive Data][Network Restrictions & Alternative Solutions].

____

## Network Restrictions & Troubleshooting

<aside aria-label="Important" class="nodinite-note nodinite-note--important">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-message-exclamation"></i> Important</p>
<div class="nodinite-note__content"><p><strong>Are you experiencing issues with network-restricted Storage Accounts?</strong> Due to Azure's Trusted Services retirement (March 2026), logging from APIM to Blob Storage with firewall restrictions requires alternative solutions. See our comprehensive guide: <a href="https://docs.nodinite.com/logging-and-monitoring/azure-api-management/policy/network-restrictions/">Network Restrictions &amp; Alternative Solutions</a>.</p></div>
</aside>

For the ports and hostnames to allow on each hop, see the [firewall settings for Azure API Management logging][APIM firewall].

**Quick summary of available options:**

1. **Private Endpoint with VNet Integration** ✅ Recommended - Best for production (requires Developer/Premium/Standard v2 tier)
2. **Direct [Log API Policy][]** - Works on all APIM tiers including Consumption
3. **Azure Function/Logic App Intermediary** - Flexible middle-ground solution
4. **Upgrade to Developer Tier** - Cost-effective option for dev/test (~$50/month)

👉 [Read the full troubleshooting guide][Network Restrictions & Alternative Solutions] for detailed implementation steps, pricing information, and recommendation matrix.

____

## <i class="fal fa-hand-point-right" aria-hidden="true"></i> Next Steps

<i class="fal fa-magnifying-glass-plus" aria-hidden="true"></i> [Search Fields][]  
<i class="fal fa-search" aria-hidden="true"></i> [Log Views][]  

## <i class="fal fa-link-horizontal" aria-hidden="true"></i> Related Topics

* <i class="fal fa-cloud-arrow-down" aria-hidden="true"></i> [Logging with Azure API Management Services][Azure API Management Services - Logging]  
* <i class="fal fa-file-code" aria-hidden="true"></i> [JSON Log Event][]  
* <i class="fal fa-coins" aria-hidden="true"></i> [Reduce Azure API Management Logging Costs][]  

* [Event Hub Policy][]  
* [Log API Policy][]  

Interested in logging from other Azure Related Services?

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

[1]:https://docs.nodinite.com/media/Documentation%20Pictures/LogAgent/AzureAPIMgmt/Blob/ManagedIdentityClientId.png
[2]:https://docs.nodinite.com/media/Documentation%20Pictures/LogAgent/AzureAPIMgmt/Blob/ManagedIdentityStorageAccount.png
[3]:https://docs.nodinite.com/media/Documentation%20Pictures/LogAgent/AzureAPIMgmt/Blob/NamedValues.png
[4]:https://docs.nodinite.com/media/Documentation%20Pictures/LogAgent/AzureAPIMgmt/Blob/BlobStorageURL.png
[5]:https://docs.nodinite.com/media/Documentation%20Pictures/LogAgent/AzureAPIMgmt/Blob/GroupByApplicationInterchangeID.png
[6]:https://docs.nodinite.com/media/Documentation%20Pictures/LogAgent/AzureAPIMgmt/Blob/InboundPolicyFragment.png
[7]:https://docs.nodinite.com/media/Documentation%20Pictures/LogAgent/AzureAPIMgmt/Blob/ManagedIdentityAPIM.png
[8]:https://docs.nodinite.com/media/Documentation%20Pictures/LogAgent/AzureAPIMgmt/Blob/AllAPIs.png
[9]:https://docs.nodinite.com/media/Documentation%20Pictures/LogAgent/AzureAPIMgmt/Blob/AllAPIsInboundPolicy.png
[10]:https://docs.nodinite.com/media/Documentation%20Pictures/LogAgent/AzureAPIMgmt/Blob/AllOperations.png
[11]:https://docs.nodinite.com/media/Documentation%20Pictures/LogAgent/AzureAPIMgmt/Blob/OperationInboundProcessing.png
[12]:https://docs.nodinite.com/media/Documentation%20Pictures/LogAgent/AzureAPIMgmt/Blob/AllAPIsOutboundPolicy.png

[APIM firewall]:https://docs.nodinite.com/logging-and-monitoring/azure-api-management/overview/#fa-shield-check-what-firewall-settings-are-required-for-azure-api-management-logging
[APIM Troubleshooting]:https://docs.nodinite.com/logging-and-monitoring/azure-api-management/troubleshooting/overview/
[Asynchronous Logging]:https://docs.nodinite.com/core-services/log-api/features/asynchronous-logging/
[Azure Agent]:https://docs.nodinite.com/logging-and-monitoring/azure/overview/
[Azure API Management Services - Logging]:https://docs.nodinite.com/logging-and-monitoring/azure-api-management/overview/
[Endpoint Directions]:https://docs.nodinite.com/core-services/log-event/features/endpoint-directions/
[EndpointTypes]:https://docs.nodinite.com/core-services/log-event/features/endpoint-types/
[Event Hub Policy]:https://docs.nodinite.com/logging-and-monitoring/azure-api-management/policy/event-hub/
[EventDirections]:https://docs.nodinite.com/core-services/log-event/features/event-directions/
[JSON Log Event]:https://docs.nodinite.com/core-services/log-event/features/json-log-event/
[Log Agents]:https://docs.nodinite.com/administration/log-management/log-agents/features/what-is-a-log-agent/
[Log API Policy]:https://docs.nodinite.com/logging-and-monitoring/azure-api-management/policy/log-api/
[Log Event]:https://docs.nodinite.com/core-services/log-event/overview/
[Log Status Codes]:https://docs.nodinite.com/administration/log-management/log-agents/features/what-is-a-log-status-code/
[Log Views]:https://docs.nodinite.com/administration/log-management/log-views/features/what-is-a-log-view/
[LogicAppsAgent]:https://docs.nodinite.com/logging-and-monitoring/azure-logic-apps/overview/
[Message Types]:https://docs.nodinite.com/repository-model/message-types/overview/
[Network Restrictions & Alternative Solutions]:https://docs.nodinite.com/logging-and-monitoring/azure-api-management/policy/network-restrictions/
[Non Events Agent]:https://docs.nodinite.com/logging-and-monitoring/non-events/overview/
[Pickup Log Events Service Logging Agent]:https://docs.nodinite.com/logging-and-monitoring/pickup-logevents-service/overview/
[Reduce Azure API Management Logging Costs]:https://docs.nodinite.com/logging-and-monitoring/azure-api-management/troubleshooting/reduce-azure-api-management-logging-costs/
[Search Fields]:https://docs.nodinite.com/administration/log-management/search-fields/features/what-is-a-search-field/
[Serilog]:https://docs.nodinite.com/logging-and-monitoring/serilog/overview/