[英]How can I get stack trace of an exception along with the default error message in microsoft botframework sdk V4 using c#
I have created a bot in microsoft botframework sdk v4 using c# and it is working well but when I got any error it simply showing "sorry, it looks like something went wrong".我使用 c# 在 microsoft botframework sdk v4 中创建了一个机器人,它运行良好,但是当我遇到任何错误时,它只是显示“抱歉,看起来好像出了点问题”。 I want to get stack trace of the exception along with that default message.
我想获取异常的堆栈跟踪以及该默认消息。 How can I get that.
我怎么能得到那个。
thanks in advance,提前致谢,
I can't see why you want to show the whole stack trace as a response of your bot to a normal user, but in case this is for testing only you can simply modify the OnTurnError
handler.我不明白您为什么要将整个堆栈跟踪显示为您的机器人对普通用户的响应,但如果这仅用于测试,您可以简单地修改
OnTurnError
处理程序。 This could usually be found in your Startup.cs
class.这通常可以在您的
Startup.cs
类中找到。
// Catches any errors that occur during a conversation turn and logs them.
options.OnTurnError = async (context, exception) =>
{
logger.LogError($"Exception caught : {exception}");
await context.SendActivityAsync("Sorry, it looks like something went wrong.");
};
From there you can use exception.StackTrace
in your message.从那里你可以在你的消息中使用
exception.StackTrace
。
If you are aiming to have this in production then don't do it .如果您的目标是在生产中使用它,请不要这样做。 Instead go for a TelemetryClient like Application Insights and track exceptions there.
而是使用像Application Insights这样的 TelemetryClient 并在那里跟踪异常。 This way you can post a nice and user friendly error message (if there is such) while still having some log information's in the backend to troubleshoot the issue.
通过这种方式,您可以发布一个很好且用户友好的错误消息(如果有的话),同时在后端仍然有一些日志信息来解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.