Exemplo n.º 1
0
        private static LogRecordDataValue CreateDataValue(Exception exception)
        {
            if (exception.InnerException == null)
            {
                return(LogRecordDataValue.CreateException(exception.GetType().ToString(),
                                                          exception.Message,
                                                          LogRecordDataValue.CreateSimple("ExceptionSource", exception.Source),
                                                          LogRecordDataValue.CreateStackTrace("ExceptionStackTrace", exception.StackTrace)));
            }

            var inner      = exception;
            var exceptions = new List <Exception>();

            do
            {
                exceptions.Add(inner);
                inner = inner.InnerException;
            } while (inner != null);


            var lastException = exceptions[exceptions.Count - 1];
            var lastDataValue = LogRecordDataValue.CreateException(lastException.GetType().ToString(),
                                                                   lastException.Message,
                                                                   LogRecordDataValue.CreateSimple("ExceptionSource", lastException.Source),
                                                                   LogRecordDataValue.CreateStackTrace("ExceptionStackTrace", lastException.StackTrace));

            for (int i = exceptions.Count - 2; i >= 0; i--)
            {
                var ex        = exceptions[i];
                var dataValue = LogRecordDataValue.CreateException(ex.GetType().ToString(),
                                                                   ex.Message,
                                                                   LogRecordDataValue.CreateSimple("ExceptionSource", ex.Source),
                                                                   LogRecordDataValue.CreateStackTrace("ExceptionStackTrace", ex.StackTrace),
                                                                   lastDataValue);
                lastDataValue = dataValue;
            }

            return(lastDataValue);
        }