コード例 #1
0
        public Action <IApplicationBuilder> Configure(Action <IApplicationBuilder> next) => app =>
        {
            // Enable tracking of application start/stop to Application Insights
            if (_telemetry.IsEnabled())
            {
                _appLifetime.ApplicationStarted.Register(() =>
                {
                    var startedEvent = new EventTelemetry("Application Started");
                    _telemetry.TrackEvent(startedEvent);
                });
                _appLifetime.ApplicationStopping.Register(() =>
                {
                    var startedEvent = new EventTelemetry("Application Stopping");
                    _telemetry.TrackEvent(startedEvent);
                    _telemetry.Flush();
                });
                _appLifetime.ApplicationStopped.Register(() =>
                {
                    var stoppedEvent = new EventTelemetry("Application Stopped");
                    _telemetry.TrackEvent(stoppedEvent);
                    _telemetry.Flush();

                    // Allow some time for flushing before shutdown.
                    Thread.Sleep(1000);
                });
            }

            // Call next now so that the ILoggerFactory by Startup.Configure is configured before we go any further
            next(app);

            // Prime the cached web root file provider for static file serving
            _cachedWebRoot.PrimeCache();
        };
コード例 #2
0
        public Action <IApplicationBuilder> Configure(Action <IApplicationBuilder> next) => app =>
        {
            // Work around Application Insights issue breaking Azure Storage: https://github.com/Microsoft/ApplicationInsights-aspnetcore/issues/416
            var modules          = app.ApplicationServices.GetServices <ITelemetryModule>();
            var dependencyModule = modules.OfType <DependencyTrackingTelemetryModule>().FirstOrDefault();
            if (dependencyModule != null)
            {
                var domains = dependencyModule.ExcludeComponentCorrelationHttpHeadersOnDomains;
                domains.Add("core.windows.net");
                domains.Add("core.chinacloudapi.cn");
                domains.Add("core.cloudapi.de");
                domains.Add("core.usgovcloudapi.net");
            }

            // Enable tracking of application start/stop to Application Insights
            if (_telemetry.IsEnabled())
            {
                _appLifetime.ApplicationStarted.Register(() =>
                {
                    var startedEvent = new EventTelemetry("Application Started");
                    _telemetry.TrackEvent(startedEvent);
                });
                _appLifetime.ApplicationStopping.Register(() =>
                {
                    var stoppingEvent = new EventTelemetry("Application Stopping");
                    _telemetry.TrackEvent(stoppingEvent);
                    _telemetry.Flush();
                });
                _appLifetime.ApplicationStopped.Register(() =>
                {
                    var stoppedEvent = new EventTelemetry("Application Stopped");
                    _telemetry.TrackEvent(stoppedEvent);
                    _telemetry.Flush();

                    // Allow some time for flushing before shutdown.
                    Thread.Sleep(1000);
                });
            }

            // Call next now so that the ILoggerFactory by Startup.Configure is configured before we go any further
            next(app);

            // Prime the cached web root file provider for static file serving
            _cachedWebRoot.PrimeCache();
        };