コード例 #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(
            IApplicationBuilder app,
            IHostingEnvironment env,
            ILoggerFactory loggerFactory)
        {
            loggerFactory
            .AddAi(() => app.ApplicationServices.GetService <TelemetryClient>(), LogLevel.Trace)
            .AddDebug(LogLevel.Trace);
            app.UseApplicationInsightsTelemetryReplication(
                env.GetAppId(typeof(Startup)),
                new Uri(Configuration["ApplicationInsights:ProxyUri"], UriKind.Absolute));
            app.UseApplicationInsightsRequestTelemetry();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseExceptionHandler();
            }

            app.UseApplicationInsightsExceptionTelemetry();

            app.Run(async(context) =>
            {
                var client = context.RequestServices.GetService <TelemetryClient>();
                client.TrackEvent("Hello World Event");
                var logger = context.RequestServices.GetService <ILoggerFactory>().CreateLogger("SampleApp");
                logger.LogInformation("Hello World Event by logger");
                await context.Response.WriteAsync("Hello World!");
            });
        }
コード例 #2
0
 /// <summary>
 /// Use ApplicationInsights TelemetryReplication app.
 /// The telemetry proxy will be determined by the first request's scheme and host.
 /// </summary>
 /// <param name="app">The App builder.</param>
 /// <param name="env">The hosting environment an application running in.</param>
 /// <param name="applicationType">The type of any class in the application.</param>
 /// <param name="proxyUri">Telemetry proxy uri. It must be an absoulte uri.</param>
 /// <returns></returns>
 public static IApplicationBuilder UseApplicationInsightsTelemetryReplication(
     this IApplicationBuilder app,
     IHostingEnvironment env,
     Type applicationType,
     Uri proxyUri)
 {
     return(UseApplicationInsightsTelemetryReplication(app, env.GetAppId(applicationType), proxyUri));
 }