2017-07-19 58 views
-1

我需要处理bot框架对话框的错误,我有IDialogContext发送消息或调用另一个对话框。 目前,我有僵尸框架对话框错误处理

try 
{ 
    await Conversation.SendAsync(); 
} 
catch (Exception e) 
{ 
    HandleExceptions(e, activity); 
} 

在MessagesController,但在这个级别的Microsoft.Bot.Builder.Dialogs.DefaultIfException已经发出错误消息发送回用户。 在DefaultIfException之前以及如何拦截错误,将其处理并传播到DefaultIfException。

+2

的[错误以BOT框架对话框处理(可能的复制https://stackoverflow.com/questions/45068972/error-handling-in- BOT框架的对话框) –

回答

0

您可以使用您的异常图层捕获bot异常。下面的代码将帮助您指导进一步进行。我正在使用它,它工作正常。

try 
    { 
     // your code 
    } 
    catch (Exception ex) 
    { 
     await BotException.GenerateBotException(message.From.Name, ex); 
    } 

之后,你需要创建一个Exception类捕捉到日志中您的自定义数据库或异常详细信息发送电子邮件通知。

using System; 
using GPP.Bot.DataAccessLayer; 
using System.Collections.Generic; 
using System.Net.Mail; 
using System.Threading.Tasks; 
using System.Web.Configuration; 
using Microsoft.SharePoint.Client; 
using Microsoft.SharePoint.Client.Utilities; 

namespace Gpp.Bot.ExceptionHandling 
{ 
    public class BotException 
    { 
     public static List<ErrorLogProperties> BOTErrorLog(string Environment, string exceptionStack, string exceptionSource, string fullException, string loggedInUser, string exceptionDateTime) 
     { 
      // this code to capture data in Cutome DB 
      return DbHelper.ExecuteList<ErrorLogProperties>(
       new Command { ComandText = "Your Stored Procedure" }, 
       new Parameter<string, object>("Environment", Environment), 
       new Parameter<string, object>("exceptionStack", exceptionStack), 
       new Parameter<string, object>("exceptionSource", exceptionSource), 
       new Parameter<string, object>("fullException", fullException), 
       new Parameter<string, object>("loggedInUser", loggedInUser), 
       new Parameter<string, object>("exceptionDateTime", exceptionDateTime) 
       ); 

     } 

     public static async Task GenerateBotException(string LLID, Exception ex) 
     { 
      BotExceptionNotification(LLID.Split('*')[1], ex.StackTrace, ex.Source, ex.Message,LLID.Split('*')[0], DateTime.Now.ToString()); 
      BOTErrorLog(LLID.Split('*')[1], ex.StackTrace, ex.Source, ex.Message,LLID.Split('*')[0], DateTime.Now.ToString()); 
     } 

     public static void BotExceptionNotification(string Environment, string exceptionStack, string exceptionSource, 
      string fullException, string loggedInUser, string exceptionDateTime) 
     { 
      // Send email code goes here using above peramaeters in you html 
     } 

    } 
} 

不要让我知道如果你需要更多的帮助