I’ve recently updated 1 logging component to log Exception.ToString rather than Exception.Message.ToString(), the problem I have with exceptions now are the following:
- Exception.ToString() contain line breaks and
- Can contain a tab character that I am splitting on
- Could cause other potential hurdles at run time, that I might not have thought of, so the logging and retrieval becomes subject to data.
What I need is a reliable way to store and retrieve these errors in a text file, in such a way as to preserve the original error.toString as much as possible. Along side the error I store 3 other fields – previously when using exception.message.toString I was using a | character as a seperator character, but now since the error is longer than 1 line, the code fails.
Any help would be welcomed,
Thanks
How about about doing a character replacement on Exception.ToString() and replacing newlines with your separator “|”. The last three fields will still be last and still use the same separator.
Or separate new lines of the exception message with “|” and fields with “||”? Then call split on the line you read in first with “||”, giving your error message and fields. Finally call split on the error message with “|”, giving each line of the message.