.net - How to serialize an Exception object in C#? -


I want to serialize an exception object in C #, however, it seems that it is impossible because in the form of an exception class Not marked. Is there any way to work around it?

If something goes wrong during the execution of the application, then I should be informed with the exception.

My first rebound is to serialize it.

What I have done before is creating a custom error class. It encodes all relevant information about an exception, and does XML serialization.

  [serialable] public class error {public datetime timestamp {get; Set; } Public string message {get; Set; } Public String StackTrace {get; Set; } Public error () {this.TimeStamp = DateTime.Now; } Public error (string message): this () {this.Message = message; } Public error (System.Exception ex): This (former message) {this.StackTrace = ex.StackTrace; } Public override string toasting () {return it. Message + this.StackTrace; }}  

Comments