Exemplo n.º 1
0
        /// <summary>
        /// Submits the event to be sent to the server.
        /// </summary>
        /// <param name="ev">The event data.</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>
        public void SubmitEvent(Event ev, ContextData pluginContextData = null)
        {
            if (ev == null)
            {
                throw new ArgumentNullException("ev");
            }

            if (!Configuration.Enabled)
            {
                _log.Value.Info(typeof(ExceptionlessClient), "Configuration is disabled. The error will not be submitted.");
                return;
            }

            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;
                }
            }

            var context = new EventPluginContext(this, ev, pluginContextData);

            EventPluginManager.Run(context);
            if (context.Cancel)
            {
                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, pluginContextData))
            {
                _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);
        }
Exemplo n.º 2
0
        public void CanCancel()
        {
            var client = new ExceptionlessClient();

            foreach (var plugin in client.Configuration.Plugins)
            {
                client.Configuration.RemovePlugin(plugin.Key);
            }

            client.Configuration.AddPlugin("cancel", 1, ctx => ctx.Cancel = true);
            client.Configuration.AddPlugin("add-tag", 2, ctx => ctx.Event.Tags.Add("Was Not Canceled"));

            var context = new EventPluginContext(client, new Event());

            EventPluginManager.Run(context);
            Assert.True(context.Cancel);
            Assert.Equal(0, context.Event.Tags.Count);
        }
Exemplo n.º 3
0
        public void ShouldUseReferenceIds()
        {
            var client = new ExceptionlessClient();

            foreach (var plugin in client.Configuration.Plugins)
            {
                client.Configuration.RemovePlugin(plugin.Key);
            }

            var context = new EventPluginContext(client, new Event {
                Type = Event.KnownTypes.Error
            });

            EventPluginManager.Run(context);
            Assert.Null(context.Event.ReferenceId);

            client.Configuration.UseReferenceIds();
            context = new EventPluginContext(client, new Event {
                Type = Event.KnownTypes.Error
            });
            EventPluginManager.Run(context);
            Assert.NotNull(context.Event.ReferenceId);
        }