问题
I've created an aspect that catches exceptions and logs them. Pretty basic stuff, but I'm trying to beef it up a bit and provide better information in the logs than just dumping the stack trace will provide.
I've already added the "standard PostSharp goodies" like method name, arguments, etc.
Is it possible to ascertain the line number of the exception via PostSharp without dumping the stack trace or parsing it and getting line number?
Thank you in advance.
回答1:
Without getting the stack info, you can only get what data is available in a normal exception by using Args.Exception.[Property_Here]
var st = new StackTrace(ex, true);
var frame = st.GetFrame(0); //Not sure if 0 is correct index, but try it first
var line = frame.GetFileLineNumber();
来源:https://stackoverflow.com/questions/8230873/postsharp-onexceptionaspect-get-line-number-of-exception