using System.Net.Http.Json; namespace WGShare.Domain.FriendlyException { /// /// 异常通知 /// public class ExceptionNotice { private static HttpClient httpClient = new HttpClient() { BaseAddress = new Uri("https://oapi.dingtalk.com/robot/send?access_token=6ddafcada8f44f4bad4a7314c4d9bd19a895ded0a1ba1afdaff5dd01a5af6781"), }; /// /// 发送异常信息 /// /// 异常 /// 异常来源(用于显示) /// public static async Task 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 = "WGShare异常", text = $"WGShare异常.描述:{exp.Message}\n详情:{exp}" }, })); return reponse.IsSuccessStatusCode; } } }