Walle.Api/AI.Common/ExceptionNotice.cs

45 lines
1.3 KiB
C#

using System.Net.Http.Json;
namespace AI.Common
{
/// <summary>
/// 异常通知
/// </summary>
public class ExceptionNotice
{
private static HttpClient httpClient = new HttpClient()
{
BaseAddress = new Uri("https://oapi.dingtalk.com/robot/send?access_token=0ba23267d03084010ee5ffae60e6f4a11e541db8e062f5cde75f3205c10c42c8"),
};
/// <summary>
/// 发送异常信息
/// </summary>
/// <param name="exp">异常</param>
/// <param name="expSrc">异常来源(用于显示)</param>
/// <returns></returns>
public static async Task<bool> SendAsync(Exception exp, string expSrc)
{
#if DEBUG
Console.WriteLine("*************** Excpetion ***************");
Console.WriteLine(exp.Message, exp);
Console.WriteLine("*************** Excpetion ***************");
return true;
#endif
var reponse = await httpClient.PostAsync(string.Empty, JsonContent.Create(new
{
msgtype = "markdown",
markdown = new
{
title = "AI.Api异常",
text = $"AI.Api异常.描述:{exp.Message}\n详情:{exp}"
},
}));
return reponse.IsSuccessStatusCode;
}
}
}