-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathCheckout.cshtml.cs
More file actions
35 lines (28 loc) · 1.13 KB
/
Checkout.cshtml.cs
File metadata and controls
35 lines (28 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System.Diagnostics.Metrics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
namespace VariantAndAzureMonitorDemo.Pages
{
public class CheckoutModel : PageModel
{
private readonly Meter _meter;
private readonly ILogger<CheckoutModel> _logger;
public CheckoutModel(IMeterFactory meterFactory, ILogger<CheckoutModel> logger)
{
_meter = meterFactory?.Create("VariantAndAzureMonitorDemo") ?? throw new ArgumentNullException(nameof(meterFactory));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public IActionResult OnPost()
{
long amount = Random.Shared.Next(1, 100);
// Track the checkout event using ILogger custom event
_logger.LogCheckout(amount);
// Track the checkout amount metric
var checkoutAmountHistogram = _meter.CreateHistogram<long>("checkoutAmount");
checkoutAmountHistogram.Record(amount);
TempData["CheckedOut"] = true;
return Page();
}
}
}