コード例 #1
0
        /// <summary>
        /// Reads the Exceptionless configuration from the app.config or web.config files configuration section.
        /// </summary>
        /// <param name="config">The configuration object you want to apply the attribute settings to.</param>
        public static void ReadFromConfigSection(this ExceptionlessConfiguration config)
        {
            ExceptionlessSection section = null;

            try {
                section = ConfigurationManager.GetSection("exceptionless") as ExceptionlessSection;
            } catch (Exception ex) {
                config.Resolver.GetLog().Error(typeof(ExceptionlessExtraConfigurationExtensions), ex, String.Concat("An error occurred while retrieving the configuration section. Exception: ", ex.Message));
            }

            if (section == null)
            {
                return;
            }

            config.Enabled = section.Enabled;

            if (IsValidApiKey(section.ApiKey))
            {
                config.ApiKey = section.ApiKey;
            }

            if (!String.IsNullOrEmpty(section.ServerUrl))
            {
                config.ServerUrl = section.ServerUrl;
            }

            if (section.EnableSSL.HasValue)
            {
                config.EnableSSL = section.EnableSSL.Value;
            }

            if (section.QueueMaxAge.HasValue)
            {
                config.QueueMaxAge = section.QueueMaxAge.Value;
            }

            if (section.QueueMaxAttempts.HasValue)
            {
                config.QueueMaxAttempts = section.QueueMaxAttempts.Value;
            }

            if (!String.IsNullOrEmpty(section.StoragePath))
            {
                config.UseFolderStorage(section.StoragePath);
            }

            if (section.EnableLogging.HasValue && section.EnableLogging.Value)
            {
                if (!String.IsNullOrEmpty(section.LogPath))
                {
                    config.UseFileLogger(section.LogPath);
                }
                else if (!String.IsNullOrEmpty(section.StoragePath))
                {
                    config.UseFileLogger(Path.Combine(section.StoragePath, "exceptionless.log"));
                }
                else if (!config.Resolver.HasRegistration <IExceptionlessLog>())
                {
                    config.UseIsolatedStorageLogger();
                }
            }

            foreach (var tag in section.Tags.SplitAndTrim(',').Where(tag => !String.IsNullOrEmpty(tag)))
            {
                config.DefaultTags.Add(tag);
            }

            if (section.ExtendedData != null)
            {
                foreach (NameValueConfigurationElement setting in section.ExtendedData)
                {
                    if (!String.IsNullOrEmpty(setting.Name))
                    {
                        config.DefaultData[setting.Name] = setting.Value;
                    }
                }
            }

            if (section.Settings != null)
            {
                foreach (NameValueConfigurationElement setting in section.Settings)
                {
                    if (!String.IsNullOrEmpty(setting.Name))
                    {
                        config.Settings[setting.Name] = setting.Value;
                    }
                }
            }

            if (section.Registrations != null && section.Registrations.Count > 0)
            {
                var types = AssemblyHelper.GetTypes(config.Resolver.GetLog());

                foreach (RegistrationConfigElement resolver in section.Registrations)
                {
                    if (String.IsNullOrEmpty(resolver.Service) || String.IsNullOrEmpty(resolver.Type))
                    {
                        continue;
                    }

                    Type resolverInterface = types.FirstOrDefault(t => t.Name.Equals(resolver.Service) || t.FullName.Equals(resolver.Service));
                    if (resolverInterface == null)
                    {
                        config.Resolver.GetLog().Error(typeof(ExceptionlessExtraConfigurationExtensions), String.Format("An error occurred while retrieving service type \"{0}\".", resolver.Service));
                        continue;
                    }

                    try {
                        Type implementationType = Type.GetType(resolver.Type);
                        if (!resolverInterface.IsAssignableFrom(implementationType))
                        {
                            config.Resolver.GetLog().Error(typeof(ExceptionlessExtraConfigurationExtensions), String.Format("Type \"{0}\" does not implement \"{1}\".", resolver.Type, resolver.Service));
                            continue;
                        }

                        config.Resolver.Register(resolverInterface, implementationType);
                    } catch (Exception ex) {
                        config.Resolver.GetLog().Error(typeof(ExceptionlessExtraConfigurationExtensions), ex, String.Format("An error occurred while registering service \"{0}\" implementation \"{1}\".", resolver.Service, resolver.Type));
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Add all of the default information to the error.  This information can be controlled from the server configuration
        /// values, application configuration, and any registered plugins.
        /// </summary>
        /// <param name="error">The error model.</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.Current.
        /// </param>
        public static void AddDefaultInformation(this Error error, IDictionary <string, object> pluginContextData = null, ExceptionlessClient client = null)
        {
            if (client == null)
            {
                client = ExceptionlessClient.Current;
            }

            ClientConfiguration configuration = client.Configuration;

            if (client.Configuration.IncludePrivateInformation)
            {
                error.UserName = Environment.UserName;
            }

            try {
                error.EnvironmentInfo = MachineInfoCollector.Collect();
            } catch (Exception ex) {
                client.Log.FormattedError(typeof(ErrorExtensions), ex, "Error adding machine information: {0}", ex.Message);
            }

#if !SILVERLIGHT
            try {
                if (configuration.TraceLogLimit > 0)
                {
                    AddRecentTraceLogEntries(error);
                }
            } catch (Exception ex) {
                client.Log.FormattedError(typeof(ErrorExtensions), ex, "Error adding trace information: {0}", ex.Message);
            }
#endif

            foreach (string tag in client.Tags)
            {
                error.Tags.Add(tag);
            }

            foreach (IExceptionlessPlugin plugin in client.Plugins)
            {
                try {
                    plugin.AddDefaultInformation(new ExceptionlessPluginContext(client, pluginContextData), error);
                } catch (Exception ex) {
                    client.Log.FormattedError(typeof(ErrorExtensions), ex, "Error adding default information: {0}", ex.Message);
                }
            }

#if !SILVERLIGHT
            ExceptionlessSection settings = ClientConfigurationReader.GetApplicationConfiguration(client);
            if (settings == null)
            {
                return;
            }

            foreach (NameValueConfigurationElement cf in settings.ExtendedData)
            {
                if (!String.IsNullOrEmpty(cf.Name))
                {
                    error.ExtendedData[cf.Name] = cf.Value;
                }
            }

            foreach (string tag in settings.Tags.SplitAndTrim(','))
            {
                if (!String.IsNullOrEmpty(tag))
                {
                    error.Tags.Add(tag);
                }
            }
#endif
        }
コード例 #3
0
        /// <summary>
        /// Reads the Exceptionless configuration from the app.config or web.config file.
        /// </summary>
        /// <param name="config">The configuration object you want to apply the attribute settings to.</param>
        public static void ReadFromConfigSection(this ExceptionlessConfiguration config)
        {
            ExceptionlessSection section = null;

            try {
                section = ConfigurationManager.GetSection("exceptionless") as ExceptionlessSection;
            } catch (Exception ex) {
                config.Resolver.GetLog().Error(typeof(ExceptionlessExtraConfigurationExtensions), ex, String.Concat("An error occurred while retrieving the configuration section. Exception: ", ex.Message));
            }

            if (section == null)
            {
                return;
            }

            config.Enabled = section.Enabled;

            // Only update if it is not null
            if (!String.IsNullOrEmpty(section.ApiKey))
            {
                config.ApiKey = section.ApiKey;
            }

            // If an appsetting is present for ApiKey, then it will override the other api keys
            string apiKeyOverride = ConfigurationManager.AppSettings["Exceptionless:ApiKey"] ?? String.Empty;

            if (!String.IsNullOrEmpty(apiKeyOverride))
            {
                config.ApiKey = apiKeyOverride;
            }

            if (!String.IsNullOrEmpty(section.ServerUrl))
            {
                config.ServerUrl = section.ServerUrl;
            }

            if (section.EnableSSL.HasValue)
            {
                config.EnableSSL = section.EnableSSL.Value;
            }

            if (!String.IsNullOrEmpty(section.StoragePath))
            {
                config.UseFolderStorage(section.StoragePath);
            }

            if (section.EnableLogging.HasValue && section.EnableLogging.Value)
            {
                if (!String.IsNullOrEmpty(section.LogPath))
                {
                    config.UseFileLogger(section.LogPath);
                }
                else if (!String.IsNullOrEmpty(section.StoragePath))
                {
                    config.UseFileLogger(Path.Combine(section.StoragePath, "exceptionless.log"));
                }
                else
                {
                    config.UseIsolatedStorageLogger();
                }
            }

            foreach (var tag in section.Tags.SplitAndTrim(',').Where(tag => !String.IsNullOrEmpty(tag)))
            {
                config.DefaultTags.Add(tag);
            }

            if (section.ExtendedData != null)
            {
                foreach (NameValueConfigurationElement setting in section.ExtendedData)
                {
                    if (!String.IsNullOrEmpty(setting.Name))
                    {
                        config.DefaultData[setting.Name] = setting.Value;
                    }
                }
            }

            if (section.Settings != null)
            {
                foreach (NameValueConfigurationElement setting in section.Settings)
                {
                    if (!String.IsNullOrEmpty(setting.Name))
                    {
                        config.Settings[setting.Name] = setting.Value;
                    }
                }
            }
        }