using System; using System.Collections.Generic; using System.Linq; using System.Net.Http.Json; using System.Text; using System.Threading.Tasks; namespace YuanXuan.IM.Common.Helpers { /// /// 异常通知 /// public class ExceptionNotice { private static HttpClient httpClient = new HttpClient() { BaseAddress = new Uri("https://oapi.dingtalk.com/robot/send?access_token=339d1f43d3b2a084abaa77871ddd187b613206149962d844adf37a46a14359a1"), }; /// /// 发送异常信息 /// /// 异常 /// 异常来源(用于显示) /// public static async Task SendAsync(Exception exp, string expSrc) { var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development"; if (env == "Development") { Console.WriteLine("*************** Excpetion ***************"); Console.WriteLine(exp.Message, exp); Console.WriteLine("*************** Excpetion ***************"); return true; } var reponse = await httpClient.PostAsync(string.Empty, JsonContent.Create(new { msgtype = "markdown", markdown = new { title = "Mobile.API抛出异常", text = $"Mobile.API异常.描述:{exp.Message}\n详情:{exp}" }, })); return reponse.IsSuccessStatusCode; } } }