Exemple #1
0
        public async Task <string> LogErrorAsync(
            Exception exception,
            string currentUser = "",
            string route       = "",
            int statusCode     = 0)
        {
            if (SkipThisException(exception))
            {
                return(null);
            }

            string shortId = ShortID.GetShortID();

            // Gather extra data
            exception.Data.Add("CTS Environment", CTS.CurrentEnvironment.ToString());
            exception.Data.Add("CTS Error ID", shortId);
            if (!string.IsNullOrEmpty(currentUser))
            {
                exception.Data.Add("Current CTS User", currentUser);
            }
            if (!string.IsNullOrEmpty(route))
            {
                exception.Data.Add("Route", route);
            }
            if (statusCode != 0)
            {
                exception.Data.Add("HTTP Status Code", statusCode);
                if (StatusCodeDescriptions.ContainsKey(statusCode))
                {
                    exception.Data.Add("HTTP Status Code Description", StatusCodeDescriptions[statusCode]);
                }
            }

            // Send to Sentry.io
            if (CTS.CurrentEnvironment != ServerEnvironment.Development)
            {
                await _ravenClient.CaptureAsync(new SentryEvent(exception));
            }

            return(shortId);
        }
Exemple #2
0
        public async Task <string> LogErrorAsync(
            string message,
            string currentUser,
            string route,
            int statusCode = 0)
        {
            var shortId = ShortID.GetShortID();

            // Gather extra data
            var extra = new Dictionary <string, string>
            {
                ["CTS Environment"] = CTS.CurrentEnvironment.ToString(),
                ["CTS Error ID"]    = shortId
            };

            if (!string.IsNullOrEmpty(currentUser))
            {
                extra["Current CTS User"] = currentUser;
            }
            if (!string.IsNullOrEmpty(route))
            {
                extra["Route"] = route;
            }
            if (statusCode != 0)
            {
                extra["HTTP Status Code"] = statusCode.ToString();
                if (StatusCodeDescriptions.ContainsKey(statusCode))
                {
                    extra["HTTP Status Code Description"] = StatusCodeDescriptions[statusCode];
                }
            }

            // Send to Sentry.io
            if (CTS.CurrentEnvironment != ServerEnvironment.Development)
            {
                await _ravenClient.CaptureAsync(new SentryEvent(message) { Extra = extra });
            }

            return(shortId);
        }