coach_rob
coach_rob

Reputation: 901

PostSharp - OnExceptionAspect - Get line number of exception

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.

Upvotes: 1

Views: 555

Answers (1)

Dustin Davis
Dustin Davis

Reputation: 14585

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();       

Upvotes: 2

Related Questions