问题
I am completely new to Azure Application Insight and trying to send TrackEvent from via my Local Computer. But Azure Application Insight does not seem to receive anything.
Here is my required. Spec. My sample asp.net framework console code with application insight sdk nuget installed is setup with Telemetry client and Instrumental Id configured. After console runs, Azure application insight should show a history as intended. But itsnot showing anything. Am I missing something?
My simple console Code
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = "c453fec7-ea68-4c06-83e4-2938eef1f124";
TelemetryClient telemetry = new TelemetryClient();
telemetry.Context.User.Id = "Test User Id.";
telemetry.Context.User.Id = "Test Device Id.";
telemetry.TrackEvent("Test TrackEvent");
InstrumentationKey is correct. Telemetry.TractEvent method does not expose exception. Azure Application Insight Search(for custom event) does not show history.
Thank you.
回答1:
The cause maybe due to one of the following:
- For .net console app, when create a Application Insights in portal, you should select "General" for Application Type. Please refer screenshots below.
2.In your console code, you should add Flush() and sleep() method.
static void Main(string[] args)
{
TelemetryConfiguration.Active.InstrumentationKey = "your key";
var telemetryClient = new TelemetryClient();
telemetryClient.Context.User.Id = "uid1";
telemetryClient.Context.Device.Id = "did1";
telemetryClient.TrackEvent("AtestEvent7");
telemetryClient.Flush();
System.Threading.Thread.Sleep(5000);
}
Then wait for a while, I can see the custom event in portal:
BTW, I noticed that you define telemetry.Context.User.Id
twice in your code, maybe a typo.
来源:https://stackoverflow.com/questions/52035598/c-sharp-application-insight-failure-trackevent-does-not-send-to-azure-applicati