Exemple #1
0
#pragma warning restore CS0618 // Type or member is obsolete

        /// <summary>
        /// Create a new instance of the ElmahIoHeartbeatFilter class. The constructor is intended for DI to use when setting up the filter.
        /// </summary>
        public ElmahIoHeartbeatFilter(IOptions <ElmahIoFunctionOptions> options)
        {
            this.options = options.Value;
            if (string.IsNullOrWhiteSpace(this.options.ApiKey))
            {
                throw new ArgumentNullException(nameof(this.options.ApiKey));
            }
            if (this.options.LogId == null || this.options.LogId == Guid.Empty)
            {
                throw new ArgumentNullException(nameof(this.options.LogId));
            }
            if (string.IsNullOrWhiteSpace(this.options.HeartbeatId))
            {
                throw new ArgumentNullException(nameof(this.options.HeartbeatId));
            }
        }
Exemple #2
0
        public static async Task Ship(FunctionExceptionContext exceptionContext, HttpContext context, ElmahIoFunctionOptions options)
#pragma warning restore CS0618 // Type or member is obsolete
        {
            var exception     = exceptionContext.Exception;
            var baseException = exception?.GetBaseException();
            var createMessage = new CreateMessage
            {
                DateTime        = DateTime.UtcNow,
                Detail          = Detail(exception),
                Type            = baseException?.GetType().FullName,
                Title           = baseException.Message,
                Data            = Data(exceptionContext),
                Cookies         = Cookies(context),
                Form            = Form(context),
                Hostname        = Hostname(context),
                ServerVariables = ServerVariables(context),
                StatusCode      = StatusCode(exception, context),
                Url             = context?.Request?.Path.Value,
                QueryString     = QueryString(context),
                Method          = context?.Request?.Method,
                Severity        = Severity(exception, context),
                Source          = Source(baseException),
                Application     = options.Application,
            };

            if (options.OnFilter != null && options.OnFilter(createMessage))
            {
                return;
            }

            if (elmahIoClient == null)
            {
                elmahIoClient = ElmahioAPI.Create(options.ApiKey, new ElmahIoOptions
                {
                    Timeout   = options.Timeout,
                    UserAgent = UserAgent(),
                });

                elmahIoClient.Messages.OnMessage += (sender, args) =>
                {
                    options.OnMessage?.Invoke(args.Message);
                };
                elmahIoClient.Messages.OnMessageFail += (sender, args) =>
                {
                    options.OnError?.Invoke(args.Message, args.Error);
                };
            }

            try
            {
                await elmahIoClient.Messages.CreateAndNotifyAsync(options.LogId, createMessage);
            }
            catch (Exception e)
            {
                options.OnError?.Invoke(createMessage, e);
                // If there's a Exception while generating the error page, re-throw the original exception.
            }
        }
Exemple #3
0
 /// <summary>
 /// Create a new instance of the ElmahIoExceptionFilter class. The constructor is intended for DI to use when setting up the filter.
 /// </summary>
 public ElmahIoExceptionFilter(IOptions <ElmahIoFunctionOptions> options)
 {
     this.options = options.Value;
 }