protected override void Append(log4net.Core.LoggingEvent loggingEvent)
        {
            if (loggingEvent == null || loggingEvent.ExceptionObject == null) return;

            var exceptionData = new ExceptionData
                                    {
                                        Exception = loggingEvent.ExceptionObject,
                                        Component = loggingEvent.LoggerName,
                                        Message = loggingEvent.RenderedMessage,
                                        UserId = UserId
                                    };
            if (loggingEvent.Level <= Level.Info)
            {
                exceptionData.Severity = ExceptionSeverity.None;
            }
            else if (loggingEvent.Level <= Level.Warn)
            {
                exceptionData.Severity = ExceptionSeverity.Warning;
            }
            else if (loggingEvent.Level <= Level.Error)
            {
                exceptionData.Severity = ExceptionSeverity.Error;
            }
            else if (loggingEvent.Level <= Level.Fatal)
            {
                exceptionData.Severity = ExceptionSeverity.Fatal;
            }

            ExceptronClient.SubmitException(exceptionData);

        }
Пример #2
0
        /// <summary>
        /// Submit an exception to exceptron Servers.
        /// </summary>
        /// <param name="exception">Exception that is being reported</param>
        /// <param name="component"
        /// example="DataAccess, Configuration, Registration, etc."
        /// remarks="It is common to use the logger name that was used to log the exception as the component.">Component that experienced this exception.</param>

        /// <param name="severity">Severity of the exception being reported</param>
        /// <param name="message"
        /// example="Something went wrong while checking for application updates.">Any message that should be attached to this exceptions</param>
        /// <param name="userId"
        /// remarks="This Id does not have to be tied to the user's identity.
        /// You can use a system generated unique ID such as GUID.
        /// This field is used to report how many unique users are experiencing an error."
        /// example="
        /// 62E5C8EF-0CA2-43AB-B278-FC6994F776ED
        /// [email protected]
        /// 26437
        /// ">ID that will uniquely identify the user</param>
        /// <param name="httpContext"><see cref="System.Web.HttpContext"/> in which the exception occurred. If no <see cref="System.Web.HttpContext"/> is provided
        /// <see cref="ExceptronClient"/> will try to get the current <see cref="System.Web.HttpContext"/> from <see cref="System.Web.HttpContext.Current"/></param>
        /// <returns></returns>
        public ExceptionResponse SubmitException(Exception exception, string component, ExceptionSeverity severity = ExceptionSeverity.None, string message = null, string userId = null, HttpContext httpContext = null)
        {
            var exceptionData = new ExceptionData
            {
                Exception   = exception,
                Component   = component,
                Severity    = severity,
                Message     = message,
                UserId      = userId,
                HttpContext = httpContext
            };

            return(SubmitException(exceptionData));
        }
Пример #3
0
        /// <summary>
        /// Submit an exception to exceptron Servers.
        /// </summary>
        /// <param name="exceptionData">Exception data to be reported to the server</param>
        public ExceptionResponse SubmitException(ExceptionData exceptionData)
        {
            try
            {
                ValidateState(exceptionData);

                var report = new ExceptionReport();

                report.ap   = Configuration.ApiKey;
                report.dn   = ClientName;
                report.dv   = ClientVersion;
                report.aver = _applicationVersion;

                report.ext = exceptionData.Exception.GetType().FullName;
                report.stk = ConvertToFrames(exceptionData.Exception);
                report.exm = exceptionData.Exception.Message;

                report.cmp = exceptionData.Component;
                report.uid = exceptionData.UserId;
                report.msg = exceptionData.Message;
                report.sv  = (int)exceptionData.Severity;
                report.fv  = _maxFrameworkVersion;
                report.ft  = FrameworkType;

                SetHttpInfo(exceptionData, report);
                SetEnviromentInfo(report);

                var exceptionResponse = RestClient.Put <ExceptionResponse>(Configuration.Host, report);

                exceptionData.Exception.Data["et"] = exceptionResponse.RefId;

                return(exceptionResponse);
            }
            catch (Exception e)
            {
                Trace.WriteLine("Unable to submit exception to exceptron. ", e.ToString());

                if (Configuration.ThrowExceptions)
                {
                    throw;
                }

                return(new ExceptionResponse {
                    Exception = e
                });
            }
        }
Пример #4
0
        private void ValidateState(ExceptionData exceptionData)
        {
            if (string.IsNullOrEmpty(Configuration.ApiKey))
            {
                throw new InvalidOperationException("ApiKey has not been provided for this client.");
            }

            if (exceptionData == null)
            {
                throw new ArgumentNullException("exceptionData");
            }

            if (exceptionData.Exception == null)
            {
                throw new ArgumentException("ExceptionData.Exception Cannot be null.", "exceptionData");
            }
        }
Пример #5
0
        public static string ReportException(LogEventInfo logEvent)
        {
            try
            {
                VerifyDependencies();

                var exceptionData = new ExceptionData();

                exceptionData.Exception = logEvent.Exception;
                exceptionData.Component = logEvent.LoggerName;
                exceptionData.Message = logEvent.FormattedMessage;
                exceptionData.UserId = EnvironmentProvider.UGuid.ToString().Replace("-", string.Empty);

                if (logEvent.Level <= LogLevel.Info)
                {
                    exceptionData.Severity = ExceptionSeverity.None;
                }
                else if (logEvent.Level <= LogLevel.Warn)
                {
                    exceptionData.Severity = ExceptionSeverity.Warning;
                }
                else if (logEvent.Level <= LogLevel.Error)
                {
                    exceptionData.Severity = ExceptionSeverity.Error;
                }
                else if (logEvent.Level <= LogLevel.Fatal)
                {
                    exceptionData.Severity = ExceptionSeverity.Fatal;
                }

                return ExceptronClient.SubmitException(exceptionData).RefId;
            }
            catch (Exception e)
            {
                if (!EnvironmentProvider.IsProduction)
                {
                    throw;
                }
                if (logEvent.LoggerName != logger.Name)//prevents a recursive loop.
                {
                    logger.WarnException("Unable to report exception. ", e);
                }
            }

            return null;
        }
Пример #6
0
        protected override void Write(LogEventInfo logEvent)
        {
            if (logEvent == null || logEvent.Exception == null) return;

            InternalLogger.Debug("Sending Exception to api.exceptron.com. Process Name: {0}", Process.GetCurrentProcess().ProcessName);

            try
            {
                var exceptionData = new ExceptionData
                {
                    Exception = logEvent.Exception,
                    Component = logEvent.LoggerName,
                    Message = logEvent.FormattedMessage,
                };

                if (UserId != null)
                {
                    exceptionData.UserId = UserId.Render(logEvent);
                }

                if (logEvent.Level <= LogLevel.Info)
                {
                    exceptionData.Severity = ExceptionSeverity.None;
                }
                else if (logEvent.Level <= LogLevel.Warn)
                {
                    exceptionData.Severity = ExceptionSeverity.Warning;
                }
                else if (logEvent.Level <= LogLevel.Error)
                {
                    exceptionData.Severity = ExceptionSeverity.Error;
                }
                else if (logEvent.Level <= LogLevel.Fatal)
                {
                    exceptionData.Severity = ExceptionSeverity.Fatal;
                }

                ExceptronClient.SubmitException(exceptionData);
            }
            catch (Exception e)
            {
                InternalLogger.Warn("Unable to report exception. {0}", e);
                throw;
            }
        }
Пример #7
0
        private void SetHttpInfo(ExceptionData exceptionData, ExceptionReport report)
        {
            if (exceptionData.HttpContext == null && HttpContext.Current == null)
            {
                return;
            }

            if (exceptionData.HttpContext == null)
            {
                exceptionData.HttpContext = HttpContext.Current;
            }

            try
            {
                report.hm = exceptionData.HttpContext.Request.HttpMethod;

                //TODO:find proper way to find http status code.

                /*
                 * var httpException = exceptionData.Exception as HttpException;
                 * if (httpException != null)
                 * {
                 *  report.sc = httpException.GetHttpCode();
                 * }*/

                report.url = exceptionData.HttpContext.Request.Url.ToString();
                report.ua  = exceptionData.HttpContext.Request.UserAgent;
            }
            catch (Exception)
            {
                if (Configuration.ThrowExceptions)
                {
                    throw;
                }
            }
        }
Пример #8
0
        private void SetHttpInfo(ExceptionData exceptionData, ExceptionReport report)
        {
            if (exceptionData.HttpContext == null && HttpContext.Current == null)
                return;

            if (exceptionData.HttpContext == null)
            {
                exceptionData.HttpContext = HttpContext.Current;
            }

            try
            {

                report.hm = exceptionData.HttpContext.Request.HttpMethod;

                //TODO:find proper way to find http status code.
                /*
                var httpException = exceptionData.Exception as HttpException;                
                if (httpException != null)
                {
                    report.sc = httpException.GetHttpCode();
                }*/

                report.url = exceptionData.HttpContext.Request.Url.ToString();
                report.ua = exceptionData.HttpContext.Request.UserAgent;
            }
            catch (Exception)
            {
                if (Configuration.ThrowExceptions) throw;
            }
        }
Пример #9
0
        private void ValidateState(ExceptionData exceptionData)
        {
            if (string.IsNullOrEmpty(Configuration.ApiKey))
                throw new InvalidOperationException("ApiKey has not been provided for this client.");

            if (exceptionData == null)
                throw new ArgumentNullException("exceptionData");

            if (exceptionData.Exception == null)
                throw new ArgumentException("ExceptionData.Exception Cannot be null.", "exceptionData");
        }
Пример #10
0
        /// <summary>
        /// Submit an exception to exceptron Servers.
        /// </summary>
        /// <param name="exceptionData">Exception data to be reported to the server</param>
        public ExceptionResponse SubmitException(ExceptionData exceptionData)
        {
            try
            {
                ValidateState(exceptionData);

                var report = new ExceptionReport();

                report.ap = Configuration.ApiKey;
                report.dn = ClientName;
                report.dv = ClientVersion;
                report.aver = _applicationVersion;

                report.ext = exceptionData.Exception.GetType().FullName;
                report.stk = ConvertToFrames(exceptionData.Exception);
                report.exm = exceptionData.Exception.Message;

                report.cmp = exceptionData.Component;
                report.uid = exceptionData.UserId;
                report.msg = exceptionData.Message;
                report.sv = (int)exceptionData.Severity;
                report.fv = _maxFrameworkVersion;
                report.ft = FrameworkType;

                SetHttpInfo(exceptionData, report);
                SetEnviromentInfo(report);

                var exceptionResponse = RestClient.Put<ExceptionResponse>(Configuration.Host, report);

                exceptionData.Exception.Data["et"] = exceptionResponse.RefId;

                return exceptionResponse;
            }
            catch (Exception e)
            {
                Trace.WriteLine("Unable to submit exception to exceptron. ", e.ToString());

                if (Configuration.ThrowExceptions)
                {
                    throw;
                }

                return new ExceptionResponse { Exception = e };
            }
        }
Пример #11
0
        /// <summary>
        /// Submit an exception to exceptron Servers.
        /// </summary>
        /// <param name="exception">Exception that is being reported</param>
        /// <param name="component" 
        /// example="DataAccess, Configuration, Registration, etc." 
        /// remarks="It is common to use the logger name that was used to log the exception as the component.">Component that experienced this exception.</param>

        /// <param name="severity">Severity of the exception being reported</param>
        /// <param name="message" 
        /// example="Something went wrong while checking for application updates.">Any message that should be attached to this exceptions</param>
        /// <param name="userId"
        /// remarks="This Id does not have to be tied to the user's identity. 
        /// You can use a system generated unique ID such as GUID. 
        /// This field is used to report how many unique users are experiencing an error." 
        /// example="
        /// 62E5C8EF-0CA2-43AB-B278-FC6994F776ED
        /// [email protected]
        /// 26437
        /// ">ID that will uniquely identify the user</param>
        /// <param name="httpContext"><see cref="System.Web.HttpContext"/> in which the exception occurred. If no <see cref="System.Web.HttpContext"/> is provided
        /// <see cref="ExceptronClient"/> will try to get the current <see cref="System.Web.HttpContext"/> from <see cref="System.Web.HttpContext.Current"/></param>
        /// <returns></returns>
        public ExceptionResponse SubmitException(Exception exception, string component, ExceptionSeverity severity = ExceptionSeverity.None, string message = null, string userId = null, HttpContext httpContext = null)
        {
            var exceptionData = new ExceptionData
                                    {
                                        Exception = exception,
                                        Component = component,
                                        Severity = severity,
                                        Message = message,
                                        UserId = userId,
                                        HttpContext = httpContext
                                    };

            return SubmitException(exceptionData);
        }