示例#1
0
        public async Task PostExceptionInstance(ExceptionInstance exceptionInstance, string excepticonApiKey)
        {
            var content = new StringContent(JsonConvert.SerializeObject(exceptionInstance));

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            content.Headers.Add(CustomHeaders.ExcepticonApiKey, new[] { excepticonApiKey });
            var result = await _httpClient.PostAsync("exceptions", content);
        }
示例#2
0
        public void CaptureException(ExceptionInstance instance)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(nameof(ExcepticonClient));
            }

            if (_options.ExcludedExceptionTypeList.Contains(instance.Type, StringComparer.InvariantCultureIgnoreCase) ||
                _options.ExcludedExceptionTypeList.Contains(instance.FullyQualifiedType, StringComparer.InvariantCultureIgnoreCase))
            {
                return;
            }

            DoSendExceptionInstance(instance);
        }
        public async Task InvokeAsync(HttpContext context)
        {
            var excepticonClient = _excepticonClientAccessor();

            if (_options.FlushOnCompletedRequest)
            {
                context.Response.OnCompleted(async() =>
                {
                    await excepticonClient.FlushAsync(_options.FlushTimeout).ConfigureAwait(false);
                });
            }

            try
            {
                await _next(context).ConfigureAwait(false);

                var exceptionFeature = context.Features.Get <IExceptionHandlerFeature>();
                if (exceptionFeature?.Error != null)
                {
                    CaptureException(exceptionFeature.Error);
                }
            }
            catch (Exception e)
            {
                CaptureException(e);

                ExceptionDispatchInfo.Capture(e).Throw();
            }

            void CaptureException(Exception e)
            {
                if (!string.IsNullOrWhiteSpace(_options.ApiKey))
                {
                    var exceptionInstance = new ExceptionInstance(e, context);

                    _logger?.LogTrace("Sending exception to Excepticon.", exceptionInstance);

                    excepticonClient.CaptureException(exceptionInstance);
                }
            }
        }
示例#4
0
        public bool EnqueueExceptionInstance(ExceptionInstance instance)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(nameof(QueueManager));
            }

            if (instance == null)
            {
                return(false);
            }

            if (Interlocked.Increment(ref _currentItems) <= _options.MaxQueueItems)
            {
                _queue.Enqueue(instance);
                _queuedEventSemaphore.Release();
                return(true);
            }

            Interlocked.Decrement(ref _currentItems);
            return(false);
        }
        private async Task HandleExceptionAsync(HttpContext context, Exception exception)
        {
            var exceptionInstance = new ExceptionInstance(exception, context);

            await _exceptionInstancesExcepticonExceptionInstancesService.PostExceptionInstance(exceptionInstance, _options.ApiKey);
        }
示例#6
0
 private void DoSendExceptionInstance(ExceptionInstance instance) => QueueManager.EnqueueExceptionInstance(instance);