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.