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 void WillLockConfig() {
     var client = new ExceptionlessClient();
     client.Configuration.Resolver.Register<ISubmissionClient, NullSubmissionClient>();
     client.Configuration.ApiKey = "e3d51ea621464280bbcb79c11fd6483e";
     client.SubmitEvent(new Event());
     Assert.Throws<ArgumentException>(() => client.Configuration.ApiKey = "blah");
     Assert.Throws<ArgumentException>(() => client.Configuration.ServerUrl = "blah");
 }
        /// <summary>
        /// Adds the current request info to the event.
        /// </summary>
        /// <param name="ev">The event model.</param>
        /// <param name="client">The client.</param>
        /// <param name="context">The http context to gather information from.</param>
        public static Event AddRequestInfo(this Event ev, ExceptionlessClient client, HttpContext context) {
            if (context == null)
                return ev;

            ev.AddRequestInfo(client, context.ToWrapped());

            return ev;
        }
        /// <summary>
        /// Adds the current request info to the error.
        /// </summary>
        /// <param name="error">The error model.</param>
        /// <param name="client">The client.</param>
        /// <param name="context">The http context to gather information from.</param>
        public static Error AddRequestInfo(this Error error, ExceptionlessClient client, HttpContext context) {
            if (context == null)
                return error;

            error.AddRequestInfo(client, context.ToWrapped());

            return error;
        }
        public void EnvironmentInfo_IncorrectEventType(string eventType) {
            var client = new ExceptionlessClient();
            var context = new EventEnrichmentContext(client);
            var ev = new Event { Type = eventType };

            var enrichment = new EnvironmentInfoEnrichment();
            enrichment.Enrich(context, ev);
            Assert.Equal(0, ev.Data.Count);
        }
        public void EnvironmentInfo_ShouldAddSessionStart() {
            var client = new ExceptionlessClient();
            var context = new EventEnrichmentContext(client);
            var ev = new Event { Type = Event.KnownTypes.SessionStart };

            var enrichment = new EnvironmentInfoEnrichment();
            enrichment.Enrich(context, ev);
            Assert.Equal(1, ev.Data.Count);
            Assert.NotNull(ev.Data[Event.KnownDataKeys.EnvironmentInfo]);
        }
        public void CanConfigureClientUsingActionMethod() {
            var client = new ExceptionlessClient(c => {
                c.ApiKey = "e3d51ea621464280bbcb79c11fd6483e";
                c.ServerUrl = Settings.Current.BaseURL;
                c.EnableSSL = false;
            });

            Assert.Equal("e3d51ea621464280bbcb79c11fd6483e", client.Configuration.ApiKey);
            Assert.Equal("http://localhost:45000", client.Configuration.ServerUrl);
            Assert.False(client.Configuration.EnableSSL);
        }
        /// <summary>
        /// Adds the current request info to the error.
        /// </summary>
        /// <param name="error">The error model.</param>
        /// <param name="client">The client.</param>
        /// <param name="context">The http context to gather information from.</param>
        public static Error AddRequestInfo(this Error error, ExceptionlessClient client, HttpContextBase context = null) {
            if (context == null && HttpContext.Current != null)
                context = HttpContext.Current.ToWrapped();

            if (context == null)
                return error;

            error.RequestInfo = RequestInfoCollector.Collect(client, context);

            return error;
        }
        /// <summary>
        /// Adds the current request info to the event.
        /// </summary>
        /// <param name="ev">The event model.</param>
        /// <param name="client">The client.</param>
        /// <param name="context">The http context to gather information from.</param>
        public static Event AddRequestInfo(this Event ev, ExceptionlessClient client, HttpContextBase context = null) {
            if (context == null && HttpContext.Current != null)
                context = HttpContext.Current.ToWrapped();

            if (context == null)
                return ev;

            ev.AddRequestInfo(RequestInfoCollector.Collect(context, client.Configuration));

            return ev;
        }
        /// <summary>
        /// Creates a builder object for constructing error reports in a fluent api.
        /// </summary>
        /// <param name="exception">The exception.</param>
        /// <param name="pluginContextData">
        /// Any contextual data objects to be used by Exceptionless plugins to gather default
        /// information for inclusion in the report information.
        /// </param>
        /// <param name="client">
        /// The ExceptionlessClient instance used for configuration. If a client is not specified, it will use
        /// ExceptionlessClient.Default.
        /// </param>
        /// <returns></returns>
        public static EventBuilder ToExceptionless(this Exception exception, ContextData pluginContextData = null, ExceptionlessClient client = null) {
            if (client == null)
                client = ExceptionlessClient.Default;

            if (pluginContextData == null)
                pluginContextData = new ContextData();

            pluginContextData.SetException(exception);

            return client.CreateEvent(pluginContextData);
        }
        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(ExceptionlessWindowsExtensions), ex, "An error occurred while wiring up to the process exit event.");
            }
        }
示例#12
0
        public static void Register(this ExceptionlessClient client, bool showDialog = true)
        {
            client.Startup();
            client.RegisterApplicationThreadExceptionHandler();
            client.RegisterApplicationDispatcherUnhandledExceptionHandler();

            if (!showDialog)
            {
                return;
            }

            client.SubmittingEvent -= OnSubmittingEvent;
            client.SubmittingEvent += OnSubmittingEvent;
        }
        /// <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;

            if (client.Configuration.SessionsEnabled)
            {
                client.SubmitSessionEnd();
            }
            client.ProcessQueue();
        }
        /// <summary>
        /// Reads configuration settings, configures various plugins and wires up to platform specific exception handlers.
        /// </summary>
        /// <param name="client">The ExceptionlessClient.</param>
        /// <param name="pipelines">The IPipelines instance.</param>
        public static void RegisterNancy(this ExceptionlessClient client, IPipelines pipelines)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            client.Startup();
            client.Configuration.AddPlugin <ExceptionlessNancyPlugin>();
            client.Configuration.AddPlugin <IgnoreUserAgentPlugin>();

            pipelines.OnError      += OnError;
            pipelines.AfterRequest += AfterRequest;
        }
        public override void ActivateOptions() {
            base.ActivateOptions();
            
            if (String.IsNullOrEmpty(ApiKey) && String.IsNullOrEmpty(ServerUrl))
                return;

            _client = new ExceptionlessClient(config => {
                if (!String.IsNullOrEmpty(ApiKey) && ApiKey != "API_KEY_HERE")
                    config.ApiKey = ApiKey;
                if (!String.IsNullOrEmpty(ServerUrl))
                    config.ServerUrl = ServerUrl;
                config.UseInMemoryStorage();
            });
        }
        public static void Register(this ExceptionlessClient client, bool showDialog = true)
        {
            client.RegisterPlugin(new ExceptionlessWindowsPlugin(showDialog));
            client.Startup();

            if (showDialog)
            {
                client.UnhandledExceptionReporting -= UnhandledExceptionReporting;
                client.UnhandledExceptionReporting += UnhandledExceptionReporting;
            }

            Application.ThreadException -= OnApplicationThreadException;
            Application.ThreadException += OnApplicationThreadException;
        }
        private static void ReplaceHttpErrorHandler(HttpConfiguration config, ExceptionlessClient client) {
            FilterInfo filter = config.Filters.FirstOrDefault(f => f.Instance is IExceptionFilter);
            var handler = new ExceptionlessHandleErrorAttribute(client);

            if (filter != null) {
                if (filter.Instance is ExceptionlessHandleErrorAttribute)
                    return;

                config.Filters.Remove(filter.Instance);

                handler.WrappedFilter = (IExceptionFilter)filter.Instance;
            }

            config.Filters.Add(handler);
        }
示例#18
0
        /// <summary>
        /// Reads configuration settings, configures various plugins and wires up to platform specific exception handlers.
        /// </summary>
        /// <param name="client">The ExceptionlessClient.</param>
        /// <param name="config">The HttpConfiguration instance.</param>
        public static void RegisterWebApi(this ExceptionlessClient client, HttpConfiguration config)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            client.Startup();
            client.Configuration.AddPlugin <ExceptionlessWebApiPlugin>();
            client.Configuration.AddPlugin <IgnoreUserAgentPlugin>();

            config.Services.Add(typeof(IExceptionLogger), new ExceptionlessExceptionLogger());

            ReplaceHttpErrorHandler(config, client);
        }
        public void CanConfigureClientUsingActionMethod() {
            const string version = "1.2.3";
            
            var client = new ExceptionlessClient(c => {
                c.ApiKey = "e3d51ea621464280bbcb79c11fd6483e";
                c.ServerUrl = Settings.Current.BaseURL;
                c.EnableSSL = false;
                c.SetVersion(version);
            });

            Assert.Equal("e3d51ea621464280bbcb79c11fd6483e", client.Configuration.ApiKey);
            Assert.Equal("http://localhost:45000", client.Configuration.ServerUrl);
            Assert.False(client.Configuration.EnableSSL);
            Assert.Equal(version, client.Configuration.DefaultData[Event.KnownDataKeys.Version].ToString());
            
        }
示例#20
0
        /// <summary>
        /// Adds the current request info to the event.
        /// </summary>
        /// <param name="ev">The event model.</param>
        /// <param name="client">The client.</param>
        /// <param name="context">The http context to gather information from.</param>
        public static Event AddRequestInfo(this Event ev, ExceptionlessClient client, HttpContextBase context = null)
        {
            if (context == null && HttpContext.Current != null)
            {
                context = HttpContext.Current.ToWrapped();
            }

            if (context == null)
            {
                return(ev);
            }

            ev.AddRequestInfo(RequestInfoCollector.Collect(context, client.Configuration));

            return(ev);
        }
        /// <summary>
        /// Creates a log message event.
        /// </summary>
        /// <param name="client">The client instance.</param>
        /// <param name="source">The log source.</param>
        /// <param name="message">The log message.</param>
        /// <param name="level">The log level.</param>
        public static EventBuilder CreateLog(this ExceptionlessClient client, string source, string message, string level)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            var builder = client.CreateLog(source, message);

            if (!String.IsNullOrWhiteSpace(level))
            {
                builder.AddObject(level.Trim(), Event.KnownDataKeys.Level);
            }

            return(builder);
        }
示例#22
0
        /// <summary>
        /// Reads configuration settings, configures various plugins and wires up to platform specific exception handlers.
        /// </summary>
        /// <param name="client">The ExceptionlessClient.</param>
        /// <param name="showDialog">Controls whether a dialog is shown when an unhandled exception occurs.</param>
        public static void Register(this ExceptionlessClient client, bool showDialog = true)
        {
            client.Startup();
            client.RegisterApplicationThreadExceptionHandler();

            // make sure that queued events are sent when the app exits
            client.RegisterOnProcessExitHandler();

            if (!showDialog)
            {
                return;
            }

            client.SubmittingEvent -= OnSubmittingEvent;
            client.SubmittingEvent += OnSubmittingEvent;
        }
        /// <summary>
        /// Adds the current request info to the error.
        /// </summary>
        /// <param name="error">The error model.</param>
        /// <param name="client">The client.</param>
        /// <param name="context">The http context to gather information from.</param>
        public static Error AddRequestInfo(this Error error, ExceptionlessClient client, HttpContextBase context = null)
        {
            if (context == null && HttpContext.Current != null)
            {
                context = HttpContext.Current.ToWrapped();
            }

            if (context == null)
            {
                return(error);
            }

            error.RequestInfo = RequestInfoCollector.Collect(client, context);

            return(error);
        }
        /// <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();
            }
        }
        /// <summary>
        /// Submits session heartbeat.
        /// </summary>
        /// <param name="client">The client instance.</param>
        /// <param name="sessionIdOrUserId">The session id or user id.</param>
        public static void SubmitSessionHeartbeat(this ExceptionlessClient client, string sessionIdOrUserId = null)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            sessionIdOrUserId = sessionIdOrUserId ?? client.Configuration.CurrentSessionIdentifier;
            if (String.IsNullOrWhiteSpace(sessionIdOrUserId))
            {
                return;
            }

            var submissionClient = client.Configuration.Resolver.GetSubmissionClient();

            submissionClient.SendHeartbeat(sessionIdOrUserId, false, client.Configuration);
        }
        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);
        }
示例#27
0
        private static void ReplaceHttpErrorHandler(HttpConfiguration config, ExceptionlessClient client)
        {
            FilterInfo filter  = config.Filters.FirstOrDefault(f => f.Instance is IExceptionFilter);
            var        handler = new ExceptionlessHandleErrorAttribute(client);

            if (filter != null)
            {
                if (filter.Instance is ExceptionlessHandleErrorAttribute)
                {
                    return;
                }

                config.Filters.Remove(filter.Instance);

                handler.WrappedFilter = (IExceptionFilter)filter.Instance;
            }

            config.Filters.Add(handler);
        }
        /// <summary>
        /// Reads configuration settings, configures various plugins and wires up to platform specific exception handlers.
        /// </summary>
        /// <param name="client">The ExceptionlessClient.</param>
        /// <param name="appDomain">The AppDomain to register the exception handlers on.</param>
        public static void Startup(this ExceptionlessClient client, AppDomain appDomain = null)
        {
            if (client.Configuration.Resolver.HasDefaultRegistration <ISubmissionClient, DefaultSubmissionClient>())
            {
                client.Configuration.Resolver.Register <ISubmissionClient, SubmissionClient>();
            }

            if (client.Configuration.Resolver.HasDefaultRegistration <IEnvironmentInfoCollector, DefaultEnvironmentInfoCollector>())
            {
                client.Configuration.Resolver.Register <IEnvironmentInfoCollector, EnvironmentInfoCollector>();
            }

            client.Configuration.ReadAllConfig();
            client.Configuration.UseErrorPlugin();
            client.Configuration.UseTraceLogEntriesPlugin();
            client.Configuration.AddPlugin <VersionPlugin>();

            client.RegisterAppDomainUnhandledExceptionHandler(appDomain);
            client.RegisterTaskSchedulerUnobservedTaskExceptionHandler();
        }
        /// <summary>
        /// Reads configuration settings, configures various plugins and wires up to platform specific exception handlers.
        /// </summary>
        /// <param name="client">The ExceptionlessClient.</param>
        /// <param name="showDialog">Controls whether a dialog is shown when an unhandled exception occurs.</param>
        public static void Register(this ExceptionlessClient client, bool showDialog = true)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            client.Configuration.AddPlugin <SetEnvironmentUserPlugin>();
            client.Startup();

            client.RegisterApplicationThreadExceptionHandler();

            if (!showDialog)
            {
                return;
            }

            client.SubmittingEvent -= OnSubmittingEvent;
            client.SubmittingEvent += OnSubmittingEvent;
        }
示例#30
0
        public void ConfigurationDefaults_EnsureNoDuplicateTagsOrData() {
            var client = new ExceptionlessClient();
            var context = new EventEnrichmentContext(client);
            var ev = new Event();

            var enrichment = new ConfigurationDefaultsEnrichment();
            enrichment.Enrich(context, ev);
            Assert.Equal(0, ev.Tags.Count);

            client.Configuration.DefaultTags.Add(Event.KnownTags.Critical);
            enrichment.Enrich(context, ev);
            Assert.Equal(1, ev.Tags.Count);
            Assert.Equal(0, ev.Data.Count);

            client.Configuration.DefaultData.Add("Message", new { Exceptionless = "Is Awesome!" });
            for (int index = 0; index < 2; index++) {
                enrichment.Enrich(context, ev);
                Assert.Equal(1, ev.Tags.Count);
                Assert.Equal(1, ev.Data.Count);
            }
        }
示例#31
0
        public static void Register(this ExceptionlessClient client, bool showDialog = true)
        {
            if (client == null)
            {
                throw new ArgumentException("Exceptionless Manager cannot be null.", "client");
            }

            client.RegisterPlugin(new ExceptionlessWpfPlugin(showDialog));
            client.Startup();

            if (Application.Current == null)
            {
                return;
            }

            Application.Current.DispatcherUnhandledException -= OnDispatcherUnhandledException;
            Application.Current.DispatcherUnhandledException += OnDispatcherUnhandledException;

            System.Windows.Forms.Application.ThreadException -= OnApplicationThreadException;
            System.Windows.Forms.Application.ThreadException += OnApplicationThreadException;
        }
示例#32
0
        internal static Error ToError(ExceptionlessClient client, Exception exception, string submissionMethod = "Manual", IDictionary <string, object> contextData = null)
        {
            Error error = exception.ToErrorModel();

            error.Id                      = ObjectId.GenerateNewId().ToString();
            error.OccurrenceDate          = DateTimeOffset.Now;
            error.ExceptionlessClientInfo = ExceptionlessClientInfoCollector.Collect(client, client.Configuration.IncludePrivateInformation);
            error.ExceptionlessClientInfo.SubmissionMethod = submissionMethod;

            foreach (IExceptionlessPlugin plugin in client.Plugins)
            {
                try {
                    var ctx = new ExceptionlessPluginContext(client, contextData);
                    plugin.AfterCreated(ctx, error, exception);
                } catch (Exception ex) {
                    client.Log.FormattedError(typeof(ErrorExtensions), ex, "Error creating error model information: {0}", ex.Message);
                }
            }

            return(error);
        }
示例#33
0
        /// <summary>
        /// Adds the object to extended data.
        /// </summary>
        /// <param name="data">The error to add the object to.</param>
        /// <param name="info">The data object to add.</param>
        /// <param name="client">
        /// The ExceptionlessClient instance used for configuration. If a client is not specified, it will use
        /// ExceptionlessClient.Default.
        /// </param>
        public static void AddObject(this IData data, ExtendedDataInfo info, ExceptionlessClient client = null)
        {
            if (client == null)
            {
                client = ExceptionlessClient.Default;
            }

            if (info == null || info.Data == null)
            {
                return;
            }

            string name = info.Data.GetType().Name;

            if (!String.IsNullOrEmpty(info.Name))
            {
                name = info.Name;
            }

            string json = String.Empty;

            string[] excludedPropertyNames = info.ExcludedPropertyNames != null?client.Configuration.DataExclusions.Union(info.ExcludedPropertyNames).ToArray() : client.Configuration.DataExclusions.ToArray();

            try {
                var serializer = DependencyResolver.Default.GetJsonSerializer();
                json = serializer.Serialize(info.Data, excludedPropertyNames, info.MaxDepthToSerialize.HasValue ? info.MaxDepthToSerialize.Value : 5, info.IgnoreSerializationErrors);
            } catch (Exception ex) {
                json = ex.ToString();
            }

            if (data.Data.ContainsKey(name))
            {
                data.Data[name] = json;
            }
            else
            {
                data.Data.Add(name, json);
            }
        }
示例#34
0
        /// <summary>
        /// Adds the object to extended data.
        /// </summary>
        /// <param name="error">The error to add the object to.</param>
        /// <param name="info">The data object to add.</param>
        /// <param name="client">
        /// The ExceptionlessClient instance used for configuration. If a client is not specified, it will use
        /// ExceptionlessClient.Current.
        /// </param>
        public static void AddObject(this Error error, ExtendedDataInfo info, ExceptionlessClient client = null)
        {
            if (client == null)
            {
                client = ExceptionlessClient.Current;
            }

            if (info == null || info.Data == null)
            {
                return;
            }

            string name = info.Data.GetType().Name;

            if (!String.IsNullOrEmpty(info.Name))
            {
                name = info.Name;
            }

            string json = String.Empty;

            ICollection <string> excludedPropertyNames = info.ExcludedPropertyNames != null?client.Configuration.DataExclusions.Union(info.ExcludedPropertyNames).ToArray() : client.Configuration.DataExclusions;

            try {
                json = ModelSerializer.Current.SerializeToString(info.Data, info.MaxDepthToSerialize, excludedPropertyNames, info.IgnoreSerializationErrors);
            } catch (Exception ex) {
                json = ex.ToString();
            }

            if (error.ExtendedData.ContainsKey(name))
            {
                error.ExtendedData[name] = json;
            }
            else
            {
                error.ExtendedData.Add(name, json);
            }
        }
示例#35
0
        /// <summary>
        /// Reads configuration settings, configures various plugins and wires up to platform specific exception handlers.
        /// </summary>
        /// <param name="client">The ExceptionlessClient.</param>
        /// <param name="showDialog">Controls whether a dialog is shown when an unhandled exception occurs.</param>
        public static void Register(this ExceptionlessClient client, bool showDialog = true)
        {
            client.Configuration.AddPlugin <SetEnvironmentUserPlugin>();
            client.Startup();

            if (client.Configuration.SessionsEnabled)
            {
                client.SubmitSessionStart();
            }

            client.RegisterApplicationThreadExceptionHandler();

            // make sure that queued events are sent when the app exits
            client.RegisterOnProcessExitHandler();

            if (!showDialog)
            {
                return;
            }

            client.SubmittingEvent -= OnSubmittingEvent;
            client.SubmittingEvent += OnSubmittingEvent;
        }
        /// <summary>
        /// Reads configuration settings, configures various plugins and wires up to platform specific exception handlers.
        /// </summary>
        /// <param name="client">The ExceptionlessClient.</param>
        /// <param name="apiKey">The API key that will be used when sending events to the server.</param>
        public static void Startup(this ExceptionlessClient client, string apiKey = null)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            if (!String.IsNullOrEmpty(apiKey))
            {
                client.Configuration.ApiKey = apiKey;
            }

            client.Configuration.ReadAllConfig();

#if !PORTABLE && !NETSTANDARD1_2
            client.Configuration.UseTraceLogEntriesPlugin();
#endif

            if (client.Configuration.UpdateSettingsWhenIdleInterval == null)
            {
                client.Configuration.UpdateSettingsWhenIdleInterval = TimeSpan.FromMinutes(2);
            }

#if !PORTABLE && !NETSTANDARD1_2
            client.RegisterAppDomainUnhandledExceptionHandler();

            // make sure that queued events are sent when the app exits
            client.RegisterOnProcessExitHandler();
#endif
            client.RegisterTaskSchedulerUnobservedTaskExceptionHandler();

            if (client.Configuration.SessionsEnabled)
            {
                client.SubmitSessionStart();
            }
        }
示例#37
0
 /// <summary>
 /// Submits an exception event.
 /// </summary>
 /// <param name="client">The client instance.</param>
 /// <param name="exception">The exception.</param>
 public static void SubmitException(this ExceptionlessClient client, Exception exception)
 {
     client.CreateException(exception).Submit();
 }
示例#38
0
 /// <summary>
 /// Submits a session end event.
 /// </summary>
 /// <param name="client">The client instance.</param>
 /// <param name="sessionId">The session id.</param>
 public static void SubmitSessionEnd(this ExceptionlessClient client, string sessionId)
 {
     client.CreateSessionEnd(sessionId).Submit();
 }
示例#39
0
 /// <summary>
 /// Creates a session end event.
 /// </summary>
 /// <param name="client">The client instance.</param>
 /// <param name="sessionId">The session id.</param>
 public static EventBuilder CreateSessionEnd(this ExceptionlessClient client, string sessionId)
 {
     return(client.CreateEvent().SetType(Event.KnownTypes.SessionEnd).SetSessionId(sessionId));
 }
 public EventSubmittingEventArgs(ExceptionlessClient client, Event data, ContextData enrichmentContextData) {
     Client = client;
     Event = data;
     EnrichmentContextData = enrichmentContextData;
 }
 public void CanConfigureApiKeyFromClientConstructor() {
     var client = new ExceptionlessClient("e3d51ea621464280bbcb79c11fd6483e");
     Assert.NotNull(client);
     Assert.Equal("e3d51ea621464280bbcb79c11fd6483e", client.Configuration.ApiKey);
 }
示例#42
0
 public EventBuilder(Event ev, ExceptionlessClient client = null, ContextData pluginContextData = null) {
     Client = client ?? ExceptionlessClient.Default;
     Target = ev;
     PluginContextData = pluginContextData ?? new ContextData();
 }
示例#43
0
 public ErrorBuilder(Error error, ExceptionlessClient client = null) {
     Client = client ?? ExceptionlessClient.Current;
     Target = error;
 }
示例#44
0
 /// <summary>
 /// Submits a log message event.
 /// </summary>
 /// <param name="client">The client instance.</param>
 /// <param name="source">The log source.</param>
 /// <param name="message">The log message.</param>
 /// <param name="level">The log level.</param>
 public static void SubmitLog(this ExceptionlessClient client, string source, string message, LogLevel level)
 {
     client.CreateLog(source, message, level.ToString()).Submit();
 }
示例#45
0
 /// <summary>
 /// Creates an exception event.
 /// </summary>
 /// <param name="client">The client instance.</param>
 /// <param name="exception">The exception.</param>
 public static EventBuilder CreateException(this ExceptionlessClient client, Exception exception)
 {
     return(exception.ToExceptionless(client: client));
 }
示例#46
0
 public EventBuilder(Event ev, ExceptionlessClient client = null, ContextData enrichmentContextData = null) {
     Client = client ?? ExceptionlessClient.Default;
     Target = ev;
     EnrichmentContextData = enrichmentContextData;
 }
 public ExceptionlessMiddleware(RequestDelegate next, ExceptionlessClient client) {
     _client = client ?? ExceptionlessClient.Default;
     _next = next;
 }
示例#48
0
 public static void Unregister(this ExceptionlessClient client)
 {
     client.Shutdown();
 }
        private static Error ToErrorModelInternal(Exception exception, ExceptionlessClient client, bool isInner = false) {
            var log = client.Configuration.Resolver.GetLog();
            Type type = exception.GetType();

            var error = new Error {
                Message = exception.GetMessage(),
                Type = type.FullName
            };

            if (!isInner)
                error.Modules = GetLoadedModules(log);

            error.PopulateStackTrace(error, exception, log);

            try {
                PropertyInfo info = type.GetProperty("HResult", BindingFlags.NonPublic | BindingFlags.Instance);
                if (info != null)
                    error.Code = info.GetValue(exception, null).ToString();
            } catch (Exception) { }
            
#if NET45
            try {
                if (exception.TargetSite != null) {
                    error.TargetMethod = new Method();
                    error.TargetMethod.PopulateMethod(error, exception.TargetSite);
                }
            } catch (Exception ex) {
                log.Error(typeof(ExceptionlessClient), ex, "Error populating TargetMethod: " + ex.Message);
            }
#endif

            var exclusions = _exceptionExclusions.Union(client.Configuration.DataExclusions).ToList();
            try {
                if (exception.Data != null) {
                    foreach (object k in exception.Data.Keys) {
                        string key = k != null ? k.ToString() : null;
                        if (String.IsNullOrEmpty(key) || key.AnyWildcardMatches(exclusions, true))
                            continue;

                        var item = exception.Data[k];
                        if (item == null)
                            continue;

                        error.Data[key] = item;
                    }
                }
            } catch (Exception ex) {
                log.Error(typeof(ExceptionlessClient), ex, "Error populating Data: " + ex.Message);
            }

            try {
                var extraProperties = type.GetPublicProperties().Where(p => !p.Name.AnyWildcardMatches(exclusions, true)).ToDictionary(p => p.Name, p => {
                    try {
                        return p.GetValue(exception, null);
                    } catch { }
                    return null;
                });

                extraProperties = extraProperties.Where(kvp => !ValueIsEmpty(kvp.Value)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

                if (extraProperties.Count > 0 && !error.Data.ContainsKey(Error.KnownDataKeys.ExtraProperties)) {
                    error.AddObject(new ExtendedDataInfo {
                        Data = extraProperties,
                        Name = Error.KnownDataKeys.ExtraProperties,
                        IgnoreSerializationErrors = true,
                        MaxDepthToSerialize = 5
                    }, client);
                }
            } catch { }

            if (exception.InnerException != null)
                error.Inner = ToErrorModelInternal(exception.InnerException, client, true);

            return error;
        }
 public EventSubmittingEventArgs(ExceptionlessClient client, Event data, ContextData pluginContextData) {
     Client = client;
     Event = data;
     PluginContextData = pluginContextData;
 }
示例#51
0
 /// <summary>
 /// Submits a log message event.
 /// </summary>
 /// <param name="client">The client instance.</param>
 /// <param name="source">The log source.</param>
 /// <param name="message">The log message.</param>
 public static void SubmitLog(this ExceptionlessClient client, string source, string message)
 {
     client.CreateLog(source, message).Submit();
 }
 public EventSubmittedEventArgs(ExceptionlessClient client, Event data, ContextData pluginContextData) : base(client, data, pluginContextData) {}
示例#53
0
 /// <summary>
 /// Creates a log message event.
 /// </summary>
 /// <param name="client">The client instance.</param>
 /// <param name="message">The log message.</param>
 public static EventBuilder CreateLog(this ExceptionlessClient client, string message)
 {
     return(client.CreateEvent().SetType(Event.KnownTypes.Log).SetMessage(message));
 }
        internal static Error ToError(ExceptionlessClient client, Exception exception, string submissionMethod = "Manual", IDictionary<string, object> contextData = null) {
            Error error = exception.ToErrorModel();
            error.Id = ObjectId.GenerateNewId().ToString();
            error.OccurrenceDate = DateTimeOffset.Now;
            error.ExceptionlessClientInfo = ExceptionlessClientInfoCollector.Collect(client, client.Configuration.IncludePrivateInformation);
            error.ExceptionlessClientInfo.SubmissionMethod = submissionMethod;

            foreach (IExceptionlessPlugin plugin in client.Plugins) {
                try {
                    var ctx = new ExceptionlessPluginContext(client, contextData);
                    plugin.AfterCreated(ctx, error, exception);
                } catch (Exception ex) {
                    client.Log.FormattedError(typeof(ErrorExtensions), ex, "Error creating error model information: {0}", ex.Message);
                }
            }

            return error;
        }
        /// <summary>
        /// Creates a builder object for constructing error reports in a fluent api.
        /// </summary>
        /// <param name="exception">The exception.</param>
        /// <param name="pluginContextData">
        /// Any contextual data objects to be used by Exceptionless plugins to gather default
        /// information for inclusion in the report information.
        /// </param>
        /// <param name="client">
        /// The ExceptionlessClient instance used for configuration. If a client is not specified, it will use
        /// ExceptionlessClient.Default.
        /// </param>
        /// <returns></returns>
        public static EventBuilder ToExceptionless(this Exception exception, ContextData pluginContextData = null, ExceptionlessClient client = null)
        {
            if (client == null)
            {
                client = ExceptionlessClient.Default;
            }

            if (pluginContextData == null)
            {
                pluginContextData = new ContextData();
            }

            pluginContextData.SetException(exception);

            return(client.CreateEvent(pluginContextData));
        }
        /// <summary>
        /// Sets the properties from an exception.
        /// </summary>
        /// <param name="exception">The exception to populate properties from.</param>
        /// <param name="client">
        /// The ExceptionlessClient instance used for configuration. If a client is not specified, it will use
        /// ExceptionlessClient.Default.
        /// </param>
        public static Error ToErrorModel(this Exception exception, ExceptionlessClient client = null) {
            if (client == null)
                client = ExceptionlessClient.Default;

            return ToErrorModelInternal(exception, client);
        }