Để in đẹp chỉ Messagelà một phần của ngoại lệ sâu sắc, bạn có thể làm một cái gì đó như thế này:
public static string ToFormattedString(this Exception exception)
{
    IEnumerable<string> messages = exception
        .GetAllExceptions()
        .Where(e => !String.IsNullOrWhiteSpace(e.Message))
        .Select(e => e.Message.Trim());
    string flattened = String.Join(Environment.NewLine, messages); // <-- the separator here
    return flattened;
}
public static IEnumerable<Exception> GetAllExceptions(this Exception exception)
{
    yield return exception;
    if (exception is AggregateException aggrEx)
    {
        foreach (Exception innerEx in aggrEx.InnerExceptions.SelectMany(e => e.GetAllExceptions()))
        {
            yield return innerEx;
        }
    }
    else if (exception.InnerException != null)
    {
        foreach (Exception innerEx in exception.InnerException.GetAllExceptions())
        {
            yield return innerEx;
        }
    }
}
Điều này đệ quy đi qua tất cả các ngoại lệ bên trong (bao gồm cả trường hợp của AggregateExceptions) để in tất cả các thuộc Messagetính có trong chúng, được phân định bằng dấu ngắt dòng.
Ví dụ 
var outerAggrEx = new AggregateException(
    "Outer aggr ex occurred.",
    new AggregateException("Inner aggr ex.", new FormatException("Number isn't in correct format.")),
    new IOException("Unauthorized file access.", new SecurityException("Not administrator.")));
Console.WriteLine(outerAggrEx.ToFormattedString());
  Bên ngoài aggr ex xảy ra. 
  Nội aggr ex. 
  Số không đúng định dạng. 
  Truy cập tập tin trái phép. 
  Không phải quản trị viên.
Bạn sẽ cần lắng nghe các thuộc tính Ngoại lệ khác để biết thêm chi tiết. Ví dụ Datasẽ có một số thông tin. Bạn có thể làm:
foreach (DictionaryEntry kvp in exception.Data)
Để có được tất cả các thuộc tính dẫn xuất (không phải trên Exceptionlớp cơ sở ), bạn có thể làm:
exception
    .GetType()
    .GetProperties()
    .Where(p => p.CanRead)
    .Where(p => p.GetMethod.GetBaseDefinition().DeclaringType != typeof(Exception));