-1

即我有一个控制器动作:

    public ActionResult Details(int? id)
    {
        telemetryClient.TrackEvent("CompanyDetailPage");
        if (id == null)
        {
            return RedirectToAction("Error", "Error", new { Text = "id is not specified" });
        }
        var company = _companyService.CompanyDetail(id.Value);
        if (company == null)
        {
            return RedirectToAction("Error", "Error", new { Text = "Invalid company id" });

        }

        // create model here and return to client view
        return View(model);
    }

现在我想在以下情况下添加通知:

  1. 用户调用没有 id 的方法
  2. 用户传递的 id 无效

什么是正确的方法?

添加“CompanyDetailPageNullId”、“CompanyDetailPageInvalidId”等事件(指标)?但是对于 CompanyDetailPageInvalidId 我也需要传递 id 。

添加诸如“CompanyDetailPageError”之类的事件(指标)并传入参数有什么问题?

或者,可能,追踪踪迹?

4

1 回答 1

1

总会有很多方法可以做到这一点,没有一个比其他方法“更正确”。这一切都取决于你想怎么做。

  • 一种是将这两条信息添加到您已经作为自定义属性发送的 1 个事件中。

  • 另一种方法是为正在进行的请求设置关于已经存在的请求遥测上下文的这两条信息

    var requestTelemetry = System.Web.HttpContext.Current.GetRequestTelemetry();

之后,有很多方法可以设置各种警报,或者在失败的请求上使用天蓝色警报,或者像Microsoft Flow 和 Application Insights 连接器

于 2018-04-02T23:26:04.200 回答