in src/Relecloud.Web.CallCenter/Controllers/CartController.cs [111:142]
public IActionResult Remove(int concertId)
{
if (ModelState.IsValid)
{
try
{
var cartData = GetCartData();
if (cartData.ContainsKey(concertId))
{
cartData.Remove(concertId);
}
SetCartData(cartData);
// Most custom telemetry should go through OpenTelemetry APIs,
// but Azure Monitor's OpenTelemetry SDK does not support custom events yet.
// https://learn.microsoft.com/azure/azure-monitor/app/opentelemetry-add-modify#send-custom-telemetry-using-the-application-insights-classic-api
// https://learn.microsoft.com/azure/azure-monitor/app/opentelemetry-add-modify#whats-the-current-release-state-of-features-within-the-azure-monitor-opentelemetry-distro
this.telemetryClient.TrackEvent("RemoveFromCart", new Dictionary<string, string> { { "ConcertId", concertId.ToString() } });
// An alternative which wouldn't require AppInsights SDK usage is to log traces.
// Note that these will appear as traces in Application Insights rather than true
// separately queryable custom events. But they may work for some scenarios.
this.logger.LogInformation("Concert {ConcertId} removed from cart", concertId);
}
catch (Exception ex)
{
this.logger.LogError(ex, $"Unable to remove {concertId} to cart");
}
}
return RedirectToAction(nameof(Index));
}