Capturing the file name and line number of an Exception
Handling exceptions is a critical task in any application. When an exception is logged, it needs to have sufficient detail so it can be researched at a later time. In addition, as a developer, you want to extract and log as much detail about it as possible. Some of those details include the file name and line number where the exception occurred. Listed below is a method that handles exceptions, extracts the message, file name, and line number for logging. private void ProcessEx(Exception ex, string details = "") { int lineNumber = 0; const string lineNumberMarker = ":line "; string traceText = ex.StackTrace + ""; /...