您可以使用您的異常圖層捕獲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框架的對話框) –