logging exception in c#

前端 未结 6 1320
轮回少年
轮回少年 2020-12-29 04:52

logging exception the code below allows to save the content of an exception in a text file. Here I\'m getting only the decription of the error.

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-29 05:49

    Please note that the exception class is serializable. This means that you could easily write the exception class to disk using the builtin XmlSerializer - or use a custom serializer to write to a txt file for example.

    Logging to output can ofcourse be done by using ToString() instead of only reading the error message as mentioned in other answers.

    Exception class

    https://docs.microsoft.com/en-us/dotnet/api/system.exception?redirectedfrom=MSDN&view=netframework-4.7.2

    Info about serialization, the act of converting an object to a file on disk and vice versa.

    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/serialization/

提交回复
热议问题