/// <summary> /// Prints the contents of <paramref name="this"/> to the given <see cref="TextWriter"/>. /// </summary> /// <param name="this">The <see cref="Exception"/> to print.</param> /// <param name="writer">The <see cref="TextWriter"/> to write exception information to.</param> /// <exception cref="ArgumentNullException"> /// Thrown if either <paramref name="this"/> or <paramref name="writer"/> is <c>null</c>. /// </exception> public static void Print(this Exception self, TextWriter writer) { if (self is null) { throw new ArgumentNullException(nameof(self)); } if (writer is null) { throw new ArgumentNullException(nameof(writer)); } writer.WriteLine($"Type Name: {self.GetType().FullName}"); writer.WriteLine($"\tSource: {self.Source}"); self.AddTargetSite(writer); writer.WriteLine($"\tMessage: {self.Message}"); writer.WriteLine($"\tHelpLink: {self.HelpLink}"); self.PrintCustomProperties(writer); self.PrintStackTrace(writer); self.PrintData(writer); if (self.InnerException is not null) { writer.WriteLine(); self.InnerException.Print(writer); } }