您可以使用您的异常图层捕获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
}
}
}
不要让我知道如果你需要更多的帮助
的[错误以BOT框架对话框处理(可能的复制https://stackoverflow.com/questions/45068972/error-handling-in- BOT框架的对话框) –