I have an Insights application in my ASP.NET Core application in C # Controller and it registers basic data like pageviews, response time, etc. But I want to create some custom events and register them as well, but I canโt get any custom events that will be displayed on the Azure portal. I am currently using the free version of Application Insights.
Very straightforward
var appInsights = new TelemetryClient();
appInsights.TrackEvent(eventName, properties);
Where eventName is a string containing the custom event that I want to track, and properties is a dictionary for tracking additional properties.
After I launched the application and hit these lines several times, I can go to the azure portal and see the basic information, but when I do a search, it says that there are 0 user events and the search for any of the user events by name does not return results .
I have a class in which there is Telemetry material below
public class ApplicationInsightsTracker : IApplicationTracker
{
private readonly TelemetryClient AppInsights = new TelemetryClient();
public void TrackEvent(string eventName, string userName, Dictionary<string, string> properties = null)
{
AppInsights.Context.User.AccountId = userName;
TrackEvent(eventName, properties);
}
public void TrackRequest(string eventName, string userName, TimeSpan elapsed,
Dictionary<string, string> properties = null)
{
AppInsights.Context.User.AccountId = userName;
TrackEvent(eventName, properties);
AppInsights.TrackRequest(eventName, DateTimeOffset.Now, elapsed, "200", true);
AppInsights.Flush();
}
private void TrackEvent(string eventName, IDictionary<string, string> properties = null)
{
AppInsights.TrackEvent(eventName, properties);
AppInsights.Flush();
}
}
Then a simple example of using me
Tracker.TrackEvent("Visit HomePage", User.Identity.Name);
Edit: the above event works, but the following does not, it does not write this file at all. This calls TrackRequest as well as TrackEvent on the TelementryClient, but I don't see them at all.
Tracker?.TrackRequest("Drill Report", userName, stopwatch.Elapsed,
new Dictionary<string, string>
{
{ "DrillBy", report.DrillBy == null ? "None" : report.DrillBy.FriendlyName }
});
I'll take it a little bit. I see that some of these events have passed, but I recorded their bundle back to back, and I see only 2 out of 6 that I should see? Any ideas what could happen?