我试图捕获Xamarin应用程序在发生未处理的异常时抛出的堆栈跟踪,以便可以将日志写入磁盘以供以后报告。
目前,我正在将异常和消息写入类似这样的字符串中:
private void OutputException(StringBuilder report, Exception exception)
{
if (exception != null)
{
report.Append("\n\n");
report.Append("\n\n");
report.Append(exception.Message);
report.Append("\n\n");
report.Append(exception.StackTrace);
OutputException(report, exception.InnerException);
}
}
我正在使用与此处所述相同的技术:
将事件侦听器附加到
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
代码捕获了堆栈跟踪,但是当我查看记录的跟踪时,它不包含我的任何类或方法名称:
at (wrapper dynamic-method) System.Object.26(intptr,intptr,intptr)
at (wrapper native-to-managed) System.Object.26(intptr,intptr,intptr)
--- End of stack trace from previous location where exception was thrown ---
at Java.Interop.JniEnvironment+InstanceMethods.CallObjectMethod
(Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method,
Java.Interop.JniArgumentValue* args) [0x00069] in <8acc8089c2ed40d08469fbaa6710a44c>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self,
Java.Interop.JniArgumentValue* parameters) [0x0002a] in <8acc8089c2ed40d08469fbaa6710a44c>:0
at Java.Lang.Throwable.get_Message () [0x0000a] in <6f8818d6ffa14f4bad6fb5f5d0f0e665>:0
--- End of managed Java.Lang.Exception stack trace ---
java.lang.Exception:
如何处理异常并使其产生代码中的类名?我不需要行号,我只需要类和方法名。