I'm using App Insights in a .net core web app and I can successfully see the telemetry data in the app insights logs. I would now like to be able to push up my own log events, but cannot seem to get it to work (i.e. my custom log events do not appear in app insights). My code is as follows:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddApplicationInsights(app.ApplicationServices);
loggerFactory.AddDebug();
var logger = loggerFactory.CreateLogger<Startup>();
logger.LogInformation("I am a log event");
I've also tried setting the log level explicitly like:
loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Debug);
But I never see the text "I am a log event" in app insights.
Can anyone tell me how I can fix this?
Documentation section: Explore .NET trace logs in Application Insights
TelemetryClient
directly. It has more options, not only TrackTrace
that is used by loggers.//TelemetryClient telemetryClient = new Microsoft.ApplicationInsights.TelemetryClient();
...
telemetryClient.TrackEvent("<EventName>");
telemetryClient.TrackMetric("<metric name>", 1);
telemetryClient.TrackTrace("message", SeverityLevel.Information);
Documentation section: Application Insights API for custom events and metrics
For the live example, you may look into feature test int ApplicationInsights-aspnetcore
repo.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加