private async Task HandleExceptionAsync(HttpContext context, Exception exception)
        {
            var exceptionInstance = new ExceptionInstance(exception, context);

            await _exceptionInstancesExcepticonExceptionInstancesService.PostExceptionInstance(exceptionInstance, _options.ApiKey);
        }
Esempio n. 2
0
        private async Task WorkerAsync(CancellationToken cancellation)
        {
            var shutdownTimeout   = new CancellationTokenSource();
            var shutdownRequested = false;

            try
            {
                while (!shutdownTimeout.IsCancellationRequested)
                {
                    if (!shutdownRequested)
                    {
                        try
                        {
                            await _queuedEventSemaphore.WaitAsync(cancellation).ConfigureAwait(false);
                        }
                        catch (OperationCanceledException)
                        {
                            if (_options.ShutdownTimeout == TimeSpan.Zero)
                            {
                                return;
                            }

                            shutdownTimeout.CancelAfter(_options.ShutdownTimeout);
                            shutdownRequested = true;
                        }
                    }

                    if (_queue.TryPeek(out var exceptionInstance))
                    {
                        try
                        {
                            var task = _excepticonExceptionInstancesService.PostExceptionInstance(exceptionInstance, _options.ApiKey);
                            await task.ConfigureAwait(false);
                        }
                        catch (OperationCanceledException)
                        {
                            return;
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine(e.Message);
                        }
                        finally
                        {
                            _queue.TryDequeue(out exceptionInstance);
                            Interlocked.Decrement(ref _currentItems);
                            OnFlushObjectReceived?.Invoke(exceptionInstance, EventArgs.Empty);
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            finally
            {
                _queuedEventSemaphore.Dispose();
            }
        }