I have setup Application Insights in my ASP.NET Core application in the C# Controller and it is logging basic data like Page Views, Response Time, etc. But I want to create some custom events and log those as well, but I cannot get any oft he Custom Events to show up in the Azure portal. Currently I'm using the Free version of Application Insights.
The is very straight forward
var appInsights = new TelemetryClient();
appInsights.TrackEvent(eventName, properties);
Where the eventName is a string containing the custom event that I want to track and properties is a Dictionary to track some additional properties.
After I run the app and hit those lines a couple of times I can then go to the azure portal and see the basic information, but when I do a Search it says that there is 0 Custom Events and searching for any of the custom events by name returns no results.
I have a class that has the Telemetry stuff in it 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 me using it is
Tracker.TrackEvent("Visit HomePage", User.Identity.Name);
Edit: The above event is working, but the below one is not, it is not logging this one at all. This calls the TrackRequest and also the TrackEvent on the TelementryClient, but I'm not seeing these at all.
Tracker?.TrackRequest("Drill Report", userName, stopwatch.Elapsed,
new Dictionary<string, string>
{
{ "DrillBy", report.DrillBy == null ? "None" : report.DrillBy.FriendlyName }
});
I somewhat take that back. I am seeing some of these events come through, but I logged a bunch of them back to back and I only see 2 of the 6 that I should be seeing? Any ideas what could be going on?