Ejemplo n.º 1
0
 public static void ReadAllConfig(this ExceptionlessConfiguration config, params Assembly[] configAttributesAssemblies)
 {
     config.UseIsolatedStorage();
     if (configAttributesAssemblies == null || configAttributesAssemblies.Length == 0)
     {
         config.ReadFromAttributes(Assembly.GetEntryAssembly(), Assembly.GetCallingAssembly());
     }
     else
     {
         config.ReadFromAttributes(configAttributesAssemblies);
     }
     config.ReadFromConfigSection();
     config.ApplySavedServerSettings();
 }
Ejemplo n.º 2
0
        public ExceptionlessClient(ExceptionlessConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            Configuration = configuration;
            configuration.Resolver.Register(typeof(ExceptionlessConfiguration), () => Configuration);
            _log   = new Lazy <IExceptionlessLog>(() => Configuration.Resolver.GetLog());
            _queue = new Lazy <IEventQueue>(() => Configuration.Resolver.GetEventQueue());
            _lastReferenceIdManager = new Lazy <ILastReferenceIdManager>(() => Configuration.Resolver.GetLastReferenceIdManager());
            _duplicateChecker       = new Lazy <IDuplicateChecker>(() => Configuration.Resolver.GetDuplicateChecker());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Automatically send session start, session heartbeats and session end events.
        /// </summary>
        /// <param name="config">Exceptionless configuration</param>
        /// <param name="sendHeartbeats">Controls whether heartbeat events are sent on an interval.</param>
        /// <param name="heartbeatInterval">The interval at which heartbeats are sent after the last sent event. The default is 30 seconds.</param>
        /// <param name="useSessionIdManagement">Allows you to manually control the session id. This is only recommended for single user desktop environments.</param>
        public static void UseSessions(this ExceptionlessConfiguration config, bool sendHeartbeats = true, TimeSpan?heartbeatInterval = null, bool useSessionIdManagement = false)
        {
            config.SessionsEnabled = true;

            if (useSessionIdManagement)
            {
                config.AddPlugin <SessionIdManagementPlugin>();
            }

            if (sendHeartbeats)
            {
                config.AddPlugin(new HeartbeatPlugin(heartbeatInterval));
            }
        }
        public static InMemoryExceptionlessLog UseInMemoryLogger(this ExceptionlessConfiguration config, LogLevel minLogLevel = null)
        {
            if (minLogLevel == null)
            {
                minLogLevel = LogLevel.Info;
            }

            var logger = new InMemoryExceptionlessLog {
                MinimumLogLevel = minLogLevel
            };

            config.Resolver.Register <IExceptionlessLog>(logger);

            return(logger);
        }
        /// <summary>
        /// Reads the Exceptionless configuration from Environment Variables.
        /// </summary>
        /// <param name="config">The configuration object you want to apply the attribute settings to.</param>
        public static void ReadFromEnvironmentalVariables(this ExceptionlessConfiguration config)
        {
            string apiKey = GetEnvironmentalVariable("Exceptionless:ApiKey") ?? GetEnvironmentalVariable("Exceptionless__ApiKey");

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

            bool enabled;

            if (Boolean.TryParse(GetEnvironmentalVariable("Exceptionless:Enabled") ?? GetEnvironmentalVariable("Exceptionless__Enabled"), out enabled) && !enabled)
            {
                config.Enabled = false;
            }

            bool   processQueueOnCompletedRequest;
            string processQueueOnCompletedRequestValue = GetEnvironmentalVariable("Exceptionless:ProcessQueueOnCompletedRequest") ??
                                                         GetEnvironmentalVariable("Exceptionless__ProcessQueueOnCompletedRequest");

            // if we are running in a serverless environment default this config to true
            if (String.IsNullOrEmpty(processQueueOnCompletedRequestValue))
            {
                // check for AWS lambda environment
                if (!String.IsNullOrEmpty(GetEnvironmentalVariable("AWS_LAMBDA_FUNCTION_NAME ")))
                {
                    processQueueOnCompletedRequestValue = Boolean.TrueString;
                }

                // check for azure functions environment
                if (!String.IsNullOrEmpty(GetEnvironmentalVariable("FUNCTIONS_WORKER_RUNTIME")))
                {
                    processQueueOnCompletedRequestValue = Boolean.TrueString;
                }
            }

            if (Boolean.TryParse(processQueueOnCompletedRequestValue, out processQueueOnCompletedRequest) && processQueueOnCompletedRequest)
            {
                config.ProcessQueueOnCompletedRequest = true;
            }

            string serverUrl = GetEnvironmentalVariable("Exceptionless:ServerUrl") ?? GetEnvironmentalVariable("Exceptionless__ServerUrl");

            if (!String.IsNullOrEmpty(serverUrl))
            {
                config.ServerUrl = serverUrl;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds the current request info as extended data to the event.
        /// </summary>
        /// <param name="ev">The event model.</param>
        /// <param name="context">The http context to gather information from.</param>
        /// <param name="config">The config.</param>
        public static Event AddRequestInfo(this Event ev, HttpContext context, ExceptionlessConfiguration config = null)
        {
            if (context == null)
            {
                return(ev);
            }

            if (config == null)
            {
                config = ExceptionlessClient.Default.Configuration;
            }

            ev.AddRequestInfo(context.GetRequestInfo(config));

            return(ev);
        }
        internal static Uri GetServiceEndPoint(this ExceptionlessConfiguration config)
        {
            var builder = new UriBuilder(config.ServerUrl)
            {
                Path = "/api/v2/"
            };

            // EnableSSL
            if (config.EnableSSL && builder.Port == 80 && !builder.Host.Contains("local"))
            {
                builder.Port   = 443;
                builder.Scheme = "https";
            }

            return(builder.Uri);
        }
Ejemplo n.º 8
0
        public static void UseTraceLogEntriesPlugin(this ExceptionlessConfiguration config, int?defaultMaxEntriesToInclude = null)
        {
            int maxEntriesToInclude = config.Settings.GetInt32(TraceLogPlugin.MaxEntriesToIncludeKey, defaultMaxEntriesToInclude ?? 0);

            if (!Trace.Listeners.OfType <ExceptionlessTraceListener>().Any())
            {
                Trace.Listeners.Add(new ExceptionlessTraceListener(maxEntriesToInclude));
            }

            if (!config.Settings.ContainsKey(TraceLogPlugin.MaxEntriesToIncludeKey) && defaultMaxEntriesToInclude.HasValue)
            {
                config.Settings.Add(TraceLogPlugin.MaxEntriesToIncludeKey, maxEntriesToInclude.ToString());
            }

            config.AddPlugin(typeof(TraceLogPlugin).Name, 70, c => new TraceLogPlugin(c));
        }
Ejemplo n.º 9
0
        public ExceptionlessClient(ExceptionlessConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            Configuration = configuration;
            configuration.Resolver.Register(typeof(ExceptionlessConfiguration), () => Configuration);
            _log   = new Lazy <IExceptionlessLog>(() => Configuration.Resolver.GetLog());
            _queue = new Lazy <IEventQueue>(() => {
                // config can't be changed after the queue starts up.
                Configuration.LockConfig();
                return(Configuration.Resolver.GetEventQueue());
            });

            _submissionClient       = new Lazy <ISubmissionClient>(() => Configuration.Resolver.GetSubmissionClient());
            _lastReferenceIdManager = new Lazy <ILastReferenceIdManager>(() => Configuration.Resolver.GetLastReferenceIdManager());
        }
        public static void UseTraceLogEntriesPlugin(this ExceptionlessConfiguration config, int?defaultMaxEntriesToInclude = null)
        {
            try {
                int maxEntriesToInclude = config.Settings.GetInt32(TraceLogPlugin.MaxEntriesToIncludeKey, defaultMaxEntriesToInclude ?? 0);

                if (!Trace.Listeners.OfType <ExceptionlessTraceListener>().Any())
                {
                    Trace.Listeners.Add(new ExceptionlessTraceListener(maxEntriesToInclude));
                }

                if (!config.Settings.ContainsKey(TraceLogPlugin.MaxEntriesToIncludeKey) && defaultMaxEntriesToInclude.HasValue)
                {
                    config.Settings.Add(TraceLogPlugin.MaxEntriesToIncludeKey, maxEntriesToInclude.ToString());
                }

                config.AddPlugin(typeof(TraceLogPlugin).Name, 70, c => new TraceLogPlugin(c));
            } catch (Exception ex) {
                config.Resolver.GetLog().Error(typeof(ExceptionlessConfigurationExtensions), ex, String.Concat("Error adding ExceptionlessTraceListener: ", ex.Message));
            }
        }
Ejemplo n.º 11
0
        public static void ReadAllConfig(this ExceptionlessConfiguration config, params Assembly[] configAttributesAssemblies)
        {
            if (!config.Resolver.HasRegistration <IObjectStorage>())
            {
                config.UseIsolatedStorage();
            }

            if (configAttributesAssemblies == null || configAttributesAssemblies.Length == 0)
            {
                config.ReadFromAttributes(Assembly.GetEntryAssembly(), Assembly.GetCallingAssembly());
            }
            else
            {
                config.ReadFromAttributes(configAttributesAssemblies);
            }

            config.ReadFromConfigSection();
            config.ReadFromAppSettings();
            config.ReadFromEnvironmentalVariables();
            config.ApplySavedServerSettings();
        }
        public static string GetInstallId(this ExceptionlessConfiguration config)
        {
            if (config == null)
            {
                return(null);
            }

            var persistedClientData = config.Resolver.Resolve <PersistedDictionary>();

            if (persistedClientData == null)
            {
                return(null);
            }

            if (!persistedClientData.ContainsKey(INSTALL_ID_KEY))
            {
                persistedClientData[INSTALL_ID_KEY] = Guid.NewGuid().ToString("N");
            }

            return(persistedClientData[INSTALL_ID_KEY]);
        }
 /// <summary>
 /// Add a custom server certificate validation against the thumbprint of any of the ca certificates.
 /// </summary>
 /// <param name="config">The configuration object you want to apply the attribute settings to.</param>
 /// <param name="thumbprint">Thumbprint of the ca certificate. <example>e.g. "afe5d244a8d1194230ff479fe2f897bbcd7a8cb4"</example></param>
 public static void TrustCAThumbprint(this ExceptionlessConfiguration config, string thumbprint)
 {
     config.ServerCertificateValidationCallback = x => {
         if (x.SslPolicyErrors == SslPolicyErrors.None)
         {
             return(true);
         }
         if (x.Chain == null || thumbprint == null)
         {
             return(false);
         }
         foreach (var ca in x.Chain.ChainElements)
         {
             if (thumbprint.Equals(ca.Certificate.Thumbprint, StringComparison.OrdinalIgnoreCase))
             {
                 return(true);
             }
         }
         return(false);
     };
 }
        /// <summary>
        /// Reads the <see cref="ExceptionlessAttribute" /> and <see cref="ExceptionlessSettingAttribute" />
        /// from the assembly.
        /// </summary>
        /// <param name="configuration">The configuration object you want to apply the attribute settings to.</param>
        /// <param name="assembly">The assembly that contains the Exceptionless configuration attributes.</param>
        public static void ReadFromAttributes(this ExceptionlessConfiguration configuration, Assembly assembly = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            if (assembly == null)
            {
                assembly = Assembly.GetCallingAssembly();
            }

            object[] attributes = assembly.GetCustomAttributes(typeof(ExceptionlessAttribute), false);
            if (attributes.Length > 0 && attributes[0] is ExceptionlessAttribute)
            {
                var attr = attributes[0] as ExceptionlessAttribute;

                configuration.Enabled = attr.Enabled;

                if (attr.ApiKey != null)
                {
                    configuration.ApiKey = attr.ApiKey;
                }
                if (attr.ServerUrl != null)
                {
                    configuration.ServerUrl = attr.ServerUrl;
                }

                configuration.EnableSSL = attr.EnableSSL;
            }

            attributes = assembly.GetCustomAttributes(typeof(ExceptionlessSettingAttribute), false);
            foreach (ExceptionlessSettingAttribute attribute in attributes.OfType <ExceptionlessSettingAttribute>())
            {
                if (!String.IsNullOrEmpty(attribute.Name))
                {
                    configuration.Settings[attribute.Name] = attribute.Value;
                }
            }
        }
        public ExceptionlessClient(ExceptionlessConfiguration configuration) {
            if (configuration == null)
                throw new ArgumentNullException("configuration");

            Configuration = configuration;
            Configuration.Changed += OnConfigurationChanged;
            Configuration.Resolver.Register(typeof(ExceptionlessConfiguration), () => Configuration);

            _log = new Lazy<IExceptionlessLog>(() => Configuration.Resolver.GetLog());
            _queue = new Lazy<IEventQueue>(() => {
                // config can't be changed after the queue starts up.
                Configuration.LockConfig();

                var q = Configuration.Resolver.GetEventQueue();
                q.EventsPosted += OnQueueEventsPosted;
                return q;
            });

            _submissionClient = new Lazy<ISubmissionClient>(() => Configuration.Resolver.GetSubmissionClient());
            _lastReferenceIdManager = new Lazy<ILastReferenceIdManager>(() => Configuration.Resolver.GetLastReferenceIdManager());
            _updateSettingsTimer = new Timer(OnUpdateSettings, null, GetInitialSettingsDelay(), Configuration.UpdateSettingsWhenIdleInterval ?? TimeSpan.FromMilliseconds(-1));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Reads the Exceptionless configuration from Environment Variables.
        /// </summary>
        /// <param name="config">The configuration object you want to apply the attribute settings to.</param>
        public static void ReadFromEnvironmentalVariables(this ExceptionlessConfiguration config)
        {
            string apiKey = GetEnvironmentalVariable("Exceptionless:ApiKey");

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

            bool enabled;

            if (Boolean.TryParse(GetEnvironmentalVariable("Exceptionless:Enabled"), out enabled))
            {
                config.Enabled = enabled;
            }

            string serverUrl = GetEnvironmentalVariable("Exceptionless:ServerUrl");

            if (!String.IsNullOrEmpty(serverUrl))
            {
                config.ServerUrl = serverUrl;
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Reads the Exceptionless configuration from the app.config or web.config files app settings.
        /// </summary>
        /// <param name="config">The configuration object you want to apply the attribute settings to.</param>
        public static void ReadFromAppSettings(this ExceptionlessConfiguration config)
        {
            string apiKey = ConfigurationManager.AppSettings["Exceptionless:ApiKey"];

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

            bool enabled;

            if (Boolean.TryParse(ConfigurationManager.AppSettings["Exceptionless:Enabled"], out enabled))
            {
                config.Enabled = enabled;
            }

            string serverUrl = ConfigurationManager.AppSettings["Exceptionless:ServerUrl"];

            if (!String.IsNullOrEmpty(serverUrl))
            {
                config.ServerUrl = serverUrl;
            }
        }
        public static void ReadAllConfig(this ExceptionlessConfiguration config, params Assembly[] configAttributesAssemblies)
        {
            if (configAttributesAssemblies == null || configAttributesAssemblies.Length == 0)
            {
                Assembly callingAssembly = null;
                try {
                    callingAssembly = Assembly.GetCallingAssembly();
                } catch (PlatformNotSupportedException) { }

                config.ReadFromAttributes(Assembly.GetEntryAssembly(), callingAssembly);
            }
            else
            {
                config.ReadFromAttributes(configAttributesAssemblies);
            }

#if !NETSTANDARD
            config.ReadFromConfigSection();
            config.ReadFromAppSettings();
#endif

            config.ReadFromEnvironmentalVariables();
            config.ApplySavedServerSettings();
        }
Ejemplo n.º 19
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;
                    }
                }
            }
        }
Ejemplo n.º 20
0
 public static void UseTraceLogger(this ExceptionlessConfiguration config, LogLevel minLogLevel = LogLevel.Info)
 {
     config.Resolver.Register <IExceptionlessLog>(new TraceExceptionlessLog {
         MinimumLogLevel = minLogLevel
     });
 }
Ejemplo n.º 21
0
 public static void UseFolderStorage(this ExceptionlessConfiguration config, string folder)
 {
     config.Resolver.Register <IObjectStorage>(new FolderObjectStorage(config.Resolver, folder));
 }
Ejemplo n.º 22
0
 public static void UseIsolatedStorage(this ExceptionlessConfiguration config)
 {
     config.Resolver.Register <IObjectStorage>(new IsolatedStorageObjectStorage(config.Resolver));
 }
Ejemplo n.º 23
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 UseErrorPlugin(this ExceptionlessConfiguration config)
 {
     config.RemovePlugin <SimpleErrorPlugin>();
     config.AddPlugin <Plugins.ErrorPlugin>();
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Sets the configuration from .net configuration settings.
        /// </summary>
        /// <param name="config">The configuration object you want to apply the settings to.</param>
        /// <param name="settings">The configuration settings</param>
        public static void ReadFromConfiguration(this ExceptionlessConfiguration config, IConfiguration settings)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            var section = settings.GetSection("Exceptionless");

            if (Boolean.TryParse(section["Enabled"], out bool enabled) && !enabled)
            {
                config.Enabled = false;
            }

            string apiKey = section["ApiKey"];

            if (!String.IsNullOrEmpty(apiKey) && apiKey != "API_KEY_HERE")
            {
                config.ApiKey = apiKey;
            }

            string serverUrl = section["ServerUrl"];

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

            if (TimeSpan.TryParse(section["QueueMaxAge"], out var queueMaxAge))
            {
                config.QueueMaxAge = queueMaxAge;
            }

            if (Int32.TryParse(section["QueueMaxAttempts"], out int queueMaxAttempts))
            {
                config.QueueMaxAttempts = queueMaxAttempts;
            }

            string storagePath = section["StoragePath"];

            if (!String.IsNullOrEmpty(storagePath))
            {
                config.Resolver.Register(typeof(IObjectStorage), () => new FolderObjectStorage(config.Resolver, storagePath));
            }

            string storageSerializer = section["StorageSerializer"];

            if (!String.IsNullOrEmpty(storageSerializer))
            {
                try {
                    var serializerType = Type.GetType(storageSerializer);
                    if (!typeof(IStorageSerializer).GetTypeInfo().IsAssignableFrom(serializerType))
                    {
                        config.Resolver.GetLog().Error(typeof(ExceptionlessConfigurationExtensions), $"The storage serializer {storageSerializer} does not implemented interface {typeof(IStorageSerializer)}.");
                    }
                    else
                    {
                        config.Resolver.Register(typeof(IStorageSerializer), serializerType);
                    }
                } catch (Exception ex) {
                    config.Resolver.GetLog().Error(typeof(ExceptionlessConfigurationExtensions), ex, $"The storage serializer {storageSerializer} type could not be resolved: ${ex.Message}");
                }
            }

            if (Boolean.TryParse(section["EnableLogging"], out bool enableLogging) && enableLogging)
            {
                string logPath = section["LogPath"];
                if (!String.IsNullOrEmpty(logPath))
                {
                    config.UseFileLogger(logPath);
                }
                else if (!String.IsNullOrEmpty(storagePath))
                {
                    config.UseFileLogger(System.IO.Path.Combine(storagePath, "exceptionless.log"));
                }
            }

            if (Boolean.TryParse(section["IncludePrivateInformation"], out bool includePrivateInformation) && !includePrivateInformation)
            {
                config.IncludePrivateInformation = false;
            }

            if (Boolean.TryParse(section["ProcessQueueOnCompletedRequest"], out bool processQueueOnCompletedRequest) && processQueueOnCompletedRequest)
            {
                config.ProcessQueueOnCompletedRequest = true;
            }

            foreach (var tag in section.GetSection("DefaultTags").GetChildren())
            {
                config.DefaultTags.Add(tag.Value);
            }

            foreach (var data in section.GetSection("DefaultData").GetChildren())
            {
                if (data.Value != null)
                {
                    config.DefaultData[data.Key] = data.Value;
                }
            }

            foreach (var setting in section.GetSection("Settings").GetChildren())
            {
                if (setting.Value != null)
                {
                    config.Settings[setting.Key] = setting.Value;
                }
            }

            // TODO: Support Registrations
        }
Ejemplo n.º 25
0
 public static void UseIsolatedStorageLogger(this ExceptionlessConfiguration config)
 {
     config.Resolver.Register <IExceptionlessLog>(new SafeExceptionlessLog(new IsolatedStorageFileExceptionlessLog("exceptionless.log")));
 }
Ejemplo n.º 26
0
 public static void UseTraceLogger(this ExceptionlessConfiguration config)
 {
     config.Resolver.Register <IExceptionlessLog, TraceExceptionlessLog>();
 }
Ejemplo n.º 27
0
 public static void UseIsolatedStorage(this ExceptionlessConfiguration config)
 {
     config.Resolver.Register <IFileStorage, IsolatedStorageFileStorage>();
 }
Ejemplo n.º 28
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 UseErrorEnrichment(this ExceptionlessConfiguration config)
 {
     config.RemoveEnrichment <SimpleErrorEnrichment>();
     config.AddEnrichment <Enrichments.ErrorEnrichment>();
 }
Ejemplo n.º 29
0
 public static void UseFileLogger(this ExceptionlessConfiguration config, string logPath)
 {
     config.Resolver.Register <IExceptionlessLog>(new SafeExceptionlessLog(new FileExceptionlessLog(logPath)));
 }
Ejemplo n.º 30
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));
                    }
                }
            }
        }