In general, the answer is log ex.ToString (). In general, an object's ToString method displays what the object wants you to know. In the case of the base class Exception, this includes a message and stack trace, in addition to any InnerException instances. Individual derived Exception classes may display additional information.
Some exceptions, such as SqlException, also contain additional information (for example, stored procedure name and line number). In these cases, it is useful to serialize the entire exception and save it as XML in your logging database. Note that not all exception classes can be serialized, so be prepared for use in the XML part.
Also, if everything you do is registering an exception, then you might want to rebuild the exception so that higher levels can handle it. Of course, this does not apply if you are already at the "top level".
source share