예제 #1
0
        public void CanUpdateSettingsFromServer() {
            var config = new ExceptionlessConfiguration(DependencyResolver.Default);
            config.ApiKey = "e3d51ea621464280bbcb79c11fd6483e";
            config.Settings["LocalSetting"] = "1";
            config.Settings["LocalSettingToOverride"] = "1";

            var submissionClient = new Mock<ISubmissionClient>();
            submissionClient.Setup(m => m.Submit(It.IsAny<IEnumerable<Event>>(), config, It.IsAny<IJsonSerializer>()))
                .Callback(() => SettingsManager.CheckVersion(1, config))
                .Returns(() => new SubmissionResponse(202, "Accepted"));
            submissionClient.Setup(m => m.GetSettings(config, It.IsAny<IJsonSerializer>()))
                .Returns(() => new SettingsResponse(true, new SettingsDictionary { { "Test", "Test" }, { "LocalSettingToOverride", "2" } }, 1));

            config.Resolver.Register<ISubmissionClient>(submissionClient.Object);
            var client = new ExceptionlessClient(config);

            Assert.Equal(2, client.Configuration.Settings.Count);
            Assert.False(client.Configuration.Settings.ContainsKey("Test"));
            Assert.Equal("1", client.Configuration.Settings["LocalSettingToOverride"]);
            client.SubmitEvent(new Event { Type = "Log", Message = "Test" });
            client.ProcessQueue();
            Assert.True(client.Configuration.Settings.ContainsKey("Test"));
            Assert.Equal("2", client.Configuration.Settings["LocalSettingToOverride"]);
            Assert.Equal(3, client.Configuration.Settings.Count);

            var storage = config.Resolver.GetFileStorage() as InMemoryFileStorage;
            Assert.True(storage.Exists(config.GetQueueName() + "\\server-settings.json"));

            config.Settings.Clear();
            config.ApplySavedServerSettings();
            Assert.True(client.Configuration.Settings.ContainsKey("Test"));
            Assert.Equal("2", client.Configuration.Settings["LocalSettingToOverride"]);
            Assert.Equal(2, client.Configuration.Settings.Count);
        }
        public static IApplicationBuilder UseExceptionless(this IApplicationBuilder app, ExceptionlessClient client = null)
        {
            if (client == null)
            {
                client = app.ApplicationServices.GetService <ExceptionlessClient>() ?? ExceptionlessClient.Default;
            }

            // Can be registered in Startup.ConfigureServices via services.AddHttpContextAccessor();
            // this is necessary to obtain Session and Request information outside of ExceptionlessMiddleware
            var contextAccessor = app.ApplicationServices.GetService <IHttpContextAccessor>();

            client.Startup();
            client.Configuration.AddPlugin(new ExceptionlessAspNetCorePlugin(contextAccessor));
            client.Configuration.AddPlugin <IgnoreUserAgentPlugin>();
            //client.Configuration.Resolver.Register<ILastReferenceIdManager, WebLastReferenceIdManager>();

            var diagnosticListener = app.ApplicationServices.GetRequiredService <DiagnosticListener>();

            diagnosticListener?.SubscribeWithAdapter(new ExceptionlessDiagnosticListener(client));

            var lifetime = app.ApplicationServices.GetRequiredService <IApplicationLifetime>();

            lifetime.ApplicationStopping.Register(() => client.ProcessQueue());

            return(app.UseMiddleware <ExceptionlessMiddleware>(client));
        }
예제 #3
0
 /// <summary>
 /// Unregisters platform specific exception handlers.
 /// </summary>
 /// <param name="client">The ExceptionlessClient.</param>
 public static void Unregister(this ExceptionlessClient client)
 {
     client.Shutdown();
     client.UnregisterOnProcessExitHandler();
     client.SubmitSessionEnd();
     client.ProcessQueue();
 }
예제 #4
0
        public static void Register(this ExceptionlessClient client)
        {
            client.Startup();

            // make sure that queued events are sent when the app exits
            AppDomain.CurrentDomain.ProcessExit += (sender, args) => {
                client.ProcessQueue();
            };
        }
 /// <summary>
 /// Unregisters platform specific exception handlers.
 /// </summary>
 /// <param name="client">The ExceptionlessClient.</param>
 public static void Unregister(this ExceptionlessClient client)
 {
     client.Shutdown();
     client.UnregisterOnProcessExitHandler();
     if (client.Configuration.SessionsEnabled)
     {
         client.SubmitSessionEnd();
     }
     client.ProcessQueue();
 }
예제 #6
0
        /// <summary>
        /// Unregisters platform specific exception handlers.
        /// </summary>
        /// <param name="client">The ExceptionlessClient.</param>
        public static void Unregister(this ExceptionlessClient client)
        {
            client.Shutdown();
            client.UnregisterApplicationThreadExceptionHandler();
            client.UnregisterOnProcessExitHandler();

            client.SubmittingEvent -= OnSubmittingEvent;

            client.SubmitSessionEnd();
            client.ProcessQueue();
        }
        private static void RegisterOnProcessExitHandler(this ExceptionlessClient client)
        {
            if (_onProcessExit == null)
            {
                _onProcessExit = (sender, args) => client.ProcessQueue();
            }

            try {
                AppDomain.CurrentDomain.ProcessExit -= _onProcessExit;
                AppDomain.CurrentDomain.ProcessExit += _onProcessExit;
            } catch (Exception ex) {
                client.Configuration.Resolver.GetLog().Error(typeof(ExceptionlessExtensions), ex, "An error occurred while wiring up to the process exit event.");
            }
        }
        public static IApplicationBuilder UseExceptionless(this IApplicationBuilder app, ExceptionlessClient client = null) {
            if (client == null)
                client = ExceptionlessClient.Default;

            client.Startup();
            client.Configuration.AddPlugin<ExceptionlessAspNetCorePlugin>();
            client.Configuration.AddPlugin<IgnoreUserAgentPlugin>();
            //client.Configuration.Resolver.Register<ILastReferenceIdManager, WebLastReferenceIdManager>();
            
            var diagnosticListener = app.ApplicationServices.GetRequiredService<DiagnosticListener>();
            diagnosticListener?.SubscribeWithAdapter(new ExceptionlessDiagnosticListener(client));

            var lifetime = app.ApplicationServices.GetRequiredService<IApplicationLifetime>();
            lifetime.ApplicationStopping.Register(() => client.ProcessQueue());

            return app.UseMiddleware<ExceptionlessMiddleware>(client);
        }
        /// <summary>
        /// Unregisters platform specific exception handlers.
        /// </summary>
        /// <param name="client">The ExceptionlessClient.</param>
        public static void Shutdown(this ExceptionlessClient client)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            client.UnregisterAppDomainUnhandledExceptionHandler();
            client.UnregisterOnProcessExitHandler();
            client.UnregisterTaskSchedulerUnobservedTaskExceptionHandler();

            client.ProcessQueue();
            if (client.Configuration.SessionsEnabled)
            {
                client.SubmitSessionEnd();
            }
        }
예제 #10
0
        public static IApplicationBuilder UseExceptionless(this IApplicationBuilder app, ExceptionlessClient client = null)
        {
            if (client == null)
            {
                client = ExceptionlessClient.Default;
            }

            client.Startup();
            client.Configuration.AddPlugin <ExceptionlessAspNetCorePlugin>();
            client.Configuration.AddPlugin <IgnoreUserAgentPlugin>();
            //client.Configuration.Resolver.Register<ILastReferenceIdManager, WebLastReferenceIdManager>();

            var diagnosticListener = app.ApplicationServices.GetRequiredService <DiagnosticListener>();

            diagnosticListener?.SubscribeWithAdapter(new ExceptionlessDiagnosticListener(client));

            var lifetime = app.ApplicationServices.GetRequiredService <IApplicationLifetime>();

            lifetime.ApplicationStopping.Register(() => client.ProcessQueue());

            return(app.UseMiddleware <ExceptionlessMiddleware>(client));
        }