ApplicationInsights-dotnet icon indicating copy to clipboard operation
ApplicationInsights-dotnet copied to clipboard

asp.net razor page

Open jhealy opened this issue 3 years ago • 0 comments

If I have an asp.net core razor page, with no controller, how do I hook the dependency injection as suggested in

https://github.com/microsoft/ApplicationInsights-dotnet/issues/1152 and https://docs.microsoft.com/en-us/azure/azure-monitor/app/asp-net-core#how-can-i-track-telemetry-thats-not-automatically-collected

The code as follows runs but the events are never written when I use the dependency injections methods for .net core. Other regular app insights events process fine.

namespace simplewebapp.Pages
{
    public class IndexModel : PageModel
    {
        private readonly ILogger<IndexModel> _logger;
        private TelemetryClient telemetry;
        public IndexModel(ILogger<IndexModel> logger, TelemetryClient telemetry)
        {
            _logger = logger;
            this.telemetry = telemetry;
            telemetry.TrackEvent("IndexPage_IndexModel");
        }

jhealy avatar Feb 02 '22 22:02 jhealy