private static IList<ExceptionData> GetInnerExceptions(Exception exception)
{
var innerExceptions = new List<ExceptionData>();
IReadOnlyCollection<Exception> aggregateInnerExceptions = (exception as AggregateException)?.InnerExceptions;
if (aggregateInnerExceptions != null)
{
foreach (Exception innerException in aggregateInnerExceptions)
{
innerExceptions.Add(Create(innerException));
}
}
else if (exception.InnerException != null)
{
innerExceptions.Add(Create(exception.InnerException));
}
return innerExceptions;
}