Ejemplo n.º 1
0
        public static JsonSerializableException Create(Exception exception)
        {
            if (exception == null)
            {
                return(null);
            }

            var serializable = new JsonSerializableException
            {
#if NET45
                HResult = exception.HResult,
#endif
                Type                             = exception.GetType().FullName,
                Message                          = exception.Message,
                HelpLink                         = exception.HelpLink,
                Source                           = exception.Source,
                StackTrace                       = exception.StackTrace,
                TargetSite                       = exception.TargetSite != null?exception.TargetSite.ToString() : null,
                                            Data = exception.Data
            };

            if (exception.InnerException != null)
            {
                serializable.InnerException = JsonSerializableException.Create(exception.InnerException);
            }
            return(serializable);
        }
Ejemplo n.º 2
0
        protected void ParseException(LoggingEvent loggingEvent, Dictionary <string, object> resultDictionary)
        {
            if (FixedFields.ContainsFlag(FixFlags.Exception))
            {
                var exception       = loggingEvent.ExceptionObject;
                var exceptionString = loggingEvent.GetExceptionString();

                // If exceptionString is empty - no exception exists at all.
                // Because GetExceptionString() returns exceptionString if exists or exception.ToString().
                if (!string.IsNullOrEmpty(exceptionString))
                {
                    resultDictionary["Exception"] = exceptionString;

                    if (SerializeObjects && exception != null)
                    {
                        resultDictionary["ExceptionObject"] = JsonSerializableException.Create(exception);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        protected void ParseMessage(LoggingEvent loggingEvent, Dictionary <string, object> resultDictionary)
        {
            if (FixedFields.ContainsFlag(FixFlags.Message))
            {
                resultDictionary["Message"] = loggingEvent.RenderedMessage;

                // Added special handling of the MessageObject since it may be an exception.
                // Exception Types require specialized serialization to prevent serialization exceptions.
                if (SerializeObjects && loggingEvent.MessageObject != null && !(loggingEvent.MessageObject is string))
                {
                    var exceptionObject = loggingEvent.MessageObject as Exception;
                    if (exceptionObject != null)
                    {
                        resultDictionary["MessageObject"] = JsonSerializableException.Create(exceptionObject);
                    }
                    else
                    {
                        resultDictionary["MessageObject"] = loggingEvent.MessageObject;
                    }
                }
            }
        }