PostSharp - OnExceptionAspect - Get line number of exception

别来无恙 提交于 2020-01-14 03:15:31

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!