Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        /// <summary>
        /// Updates the user's email address and description of an event for the specified reference id.
        /// </summary>
        /// <param name="referenceId">The reference id of the event to update.</param>
        /// <param name="email">The user's email address to set on the event.</param>
        /// <param name="description">The user's description of the event.</param>
        public bool UpdateUserEmailAndDescription(string referenceId, string email, string description)
        {
            if (String.IsNullOrEmpty(referenceId))
            {
                throw new ArgumentNullException("referenceId");
            }

            if (String.IsNullOrEmpty(email) && String.IsNullOrEmpty(description))
            {
                return(true);
            }

            if (!Configuration.Enabled)
            {
                _log.Value.Info(typeof(ExceptionlessClient), "Configuration is disabled. The event will not be updated with the user email and description.");
                return(false);
            }

            if (!Configuration.IsValid)
            {
                _log.Value.FormattedInfo(typeof(ExceptionlessClient), "Configuration is invalid: {0}. The event will not be updated with the user email and description.", String.Join(", ", Configuration.Validate().Messages));
                return(false);
            }

            if (!Configuration.IsLocked)
            {
                Configuration.LockConfig();
                if (!Configuration.IsValid)
                {
                    _log.Value.FormattedError(typeof(ExceptionlessClient), "Disabling client due to invalid configuration: {0}", String.Join(", ", Configuration.Validate().Messages));
                    return(false);
                }
            }

            try {
                var response = _submissionClient.Value.PostUserDescription(referenceId, new UserDescription(email, description), Configuration, Configuration.Resolver.GetJsonSerializer());
                if (!response.Success)
                {
                    _log.Value.FormattedError(typeof(ExceptionlessClient), response.Exception, "Failed to submit user email and description for event '{0}': {1} {2}", referenceId, response.StatusCode, response.Message);
                }

                return(response.Success);
            } catch (Exception ex) {
                _log.Value.FormattedError(typeof(ExceptionlessClient), ex, "An error occurred while updating the user email and description for event: {0}.", referenceId);
                return(false);
            }
        }
        /// <summary>
        /// Submits the event to be sent to the server.
        /// </summary>
        /// <param name="ev">The event data.</param>
        /// <param name="enrichmentContextData">
        /// Any contextual data objects to be used by Exceptionless enrichments to gather default
        /// information for inclusion in the report information.
        /// </param>
        public void SubmitEvent(Event ev, ContextData enrichmentContextData = null)
        {
            if (!Configuration.Enabled)
            {
                _log.Value.Info(typeof(ExceptionlessClient), "Configuration is disabled. The error will not be submitted.");
                return;
            }

            if (ev == null)
            {
                throw new ArgumentNullException("ev");
            }

            Configuration.LockConfig();
            if (!Configuration.Validate().IsValid)
            {
                Configuration.Enabled = false;
                _log.Value.FormattedError(typeof(ExceptionlessClient), "Disabling client due to invalid configuration: {0}", String.Join(", ", Configuration.Validate().Messages));
                return;
            }

            var context = new EventEnrichmentContext(this, enrichmentContextData);

            EventEnrichmentManager.Enrich(context, ev);

            if (_duplicateChecker.Value.IsDuplicate(ev))
            {
                return;
            }

            // ensure all required data
            if (String.IsNullOrEmpty(ev.Type))
            {
                ev.Type = Event.KnownTypes.Log;
            }
            if (ev.Date == DateTimeOffset.MinValue)
            {
                ev.Date = DateTimeOffset.Now;
            }

            if (!OnSubmittingEvent(ev, enrichmentContextData))
            {
                _log.Value.FormattedInfo(typeof(ExceptionlessClient), "Event submission cancelled by event handler: id={0} type={1}", ev.ReferenceId, ev.Type);
                return;
            }

            _log.Value.FormattedTrace(typeof(ExceptionlessClient), "Submitting event: type={0}{1}", ev.Type, !String.IsNullOrEmpty(ev.ReferenceId) ? " refid=" + ev.ReferenceId : String.Empty);
            _queue.Value.Enqueue(ev);

            if (String.IsNullOrEmpty(ev.ReferenceId))
            {
                return;
            }

            _log.Value.FormattedTrace(typeof(ExceptionlessClient), "Setting last reference id '{0}'", ev.ReferenceId);
            _lastReferenceIdManager.Value.SetLast(ev.ReferenceId);
        }
Esempio n. 4
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());
        }