简体   繁体   English

如何使用 c# 在 microsoft botframework sdk V4 中获取异常的堆栈跟踪以及默认错误消息

[英]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.

相关问题 如何使用c#发送microsoft botframework sdk v4中本地文件夹中的图像 - how to send images which are in local folder in microsoft botframework sdk v4 using c# 如何使用c#将对话消息记录到Microsoft botframework sdk v4中的Azure SQL数据库中 - how to log conversation messages into azure sql database in microsoft botframework sdk v4 using c# 如何获得异常的完整C#堆栈跟踪,就像在Visual Studio中看到的那样? - How can I get the full C# stack trace for an exception, like I see in Visual Studio? [BotFramework]:如何解决:在V4中开发的C#WebChatBot中没有在用户中显示欢迎消息,而在模拟器中却显示了欢迎消息? - [BotFramework]: How to fix:Welcome message is not getting displayed to the user in C# WebChatBot developed in V4 but displayed in Emulator? 使用 TestFlow 时如何将选项传递给对话框 - Azure botframework v4 - C# - 单元测试 - How to pass in options to a Dialog when using TestFlow - Azure botframework v4 - C# - Unit Tests [BotFramework]:在使用C#SDK V4开发的BOT中,是否可以在英雄卡或自适应卡中显示Oauth提示? - [BotFramework]: Is there a way to Display Oauth prompt in hero card or Adaptive card in a BOT Developed using SDK V4 in C#? 如何使用V4在C#的Microsoft bot框架中获取用户名? - How to get user name in Microsoft bot framework in C# using V4? 如何在 C# 中使用 Microsoft Bot Framework SDK V4 开发的 ChatBot 中添加条件 w.r.t 自适应卡片? - How to add conditions w.r.t Adaptive cards in ChatBot developed using Microsoft Bot Framework SDK V4 in C#? 如何修复 Microsoft Botframework v4 中的“DataTable”不包含“AsEnumerable”错误的定义? - How to fix 'DataTable' does not contain a definition for 'AsEnumerable' Error in Microsoft Botframework v4? [BotFrameWork]:如何在使用V4开发的C#Webchat机器人中同时显示文本提示和选择提示? - [BotFrameWork]:How to have text prompt and choice prompt both at a time in C# Webchat bot developed using V4?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM