ich hab éin kleines Problem an dem ich grad nicht weiterkomme.
Ich will alle Exceptions + InnereExceptions durchlaufen und jeweils bestimmte Werte davon auslesen und speichern (wird nachher in einer XML-Datei gespeichert)
Die Struktur Ex->InnerEx->InnerEx->.. soll dabei erhalten bleiben.
Ich hab folgende Klasse in der die Daten speichere:
public class ExceptionInfos
{
public ExceptionInfos() { }
public ExceptionInfos(string exMsg, string exType)
{
this.ExceptionType = exType;
this.ExceptionMessage = exMsg;
}
public string ExceptionMessage { get; set; }
public string ExceptionType { get; set;}
public string StackTrace { get; set; }
public string AdditionalInformation { get; set; }
public ExceptionInfos InnerException;
public List<ExceptionInfos> exCol;
}
Mein Versuch das ganze zu füllen sieht so aus:
public void WriteToXML(Exception ex)
{
ExceptionInfos exInfos = new ExceptionInfos();
exInfos.ExceptionMessage = ex.Message;
exInfos.ExceptionType = ex.GetType().ToString();
exInfos.StackTrace = ex.StackTrace;
ExceptionInfos exInfos2 = new ExceptionInfos();
Exception ex2 = ex.InnerException;
while (ex2 != null)
{
exInfos2 = new ExceptionInfos();
exInfos2.ExceptionMessage = ex2.Message;
exInfos2.ExceptionType = ex2.GetType().ToString();
exInfos2.StackTrace = ex2.StackTrace;
Console.WriteLine(exInfos2.ExceptionMessage);
ex2 = ex2.InnerException;
}
Das Problem ist hierbei das mir die InnereException immer wieder ersetzt wird und ich keine komplette Verschachtelung habe wie ich es gern hätte.
Ich komme im Moment nicht auf die Idee wie ich das lösen könnte, das ich die Verschachtelung behalte. Ich hab schon rumprobiert, aber ich komm nicht auf die Lösung.
Wäre super, wenn mir da jemand auf die Sprünge hilft...