【问题标题】:is it possible to send only error logs to event hub?是否可以仅将错误日志发送到事件中心?
【发布时间】:2020-06-26 10:12:11
【问题描述】:

我在 azure apim 中创建了一个诊断设置并将日志发送到事件中心。

但现在的要求是我只需将错误日志从 azure api 管理传递到事件中心。当前设置将所有成功和失败日志传递到事件中心。

有什么方法可以在将日志发送到事件中心之前过滤日志或仅记录错误。

【问题讨论】:

    标签: azure azure-api-management azure-eventhub azure-eventhub-capture


    【解决方案1】:

    为了实现这一点,我将检查响应状态代码,并仅在 outbound 部分出错时发送到 eventthub,例如all operations 政策:

    <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>
    

    这是针对来自后端的响应错误。如果您指的是请求/策略处理中发生的错误,您只能从on-error 部分发送。请参阅here 了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-31
      • 1970-01-01
      • 2012-05-14
      • 2019-01-29
      • 1970-01-01
      • 1970-01-01
      • 2022-01-12
      • 1970-01-01
      相关资源
      最近更新 更多