Reputation: 23
I created a diagnostics setting in azure apim and send logs to event hub.
But now the requirement is I need to pass only the error logs from azure api management to event hub.Current setting passes all the success and failure logs into event hub.
is there any way to filter logs before sending it into event hub or log only errors.
Upvotes: 2
Views: 342
Reputation: 4001
To achieve this I would check response status code and only send to eventhub in case of an error in outbound
section e.g. of the all operations
policy:
<policies>
<inbound>
<base />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
<choose>
<when condition="@(context.Response.StatusCode.ToString() >= "400")">
<log-to-eventhub logger-id ="ehLogger">
@(...)
</log-to-eventhub>
</when>
<otherwise>
</otherwise>
</choose>
</outbound>
<on-error>
<base />
<log-to-eventhub logger-id ="ehLogger">
@(...)
</log-to-eventhub>
</on-error>
</policies>
This is for response errors from the backend. If you're referring to errors happening in request / policy processing, you would only send from on-error
section. See here for more information.
Upvotes: 3