52 lines
1.6 KiB
C#
52 lines
1.6 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// 异常通知
|
|
/// </summary>
|
|
public class ExceptionNotice
|
|
{
|
|
private static HttpClient httpClient = new HttpClient()
|
|
{
|
|
BaseAddress = new Uri("https://oapi.dingtalk.com/robot/send?access_token=339d1f43d3b2a084abaa77871ddd187b613206149962d844adf37a46a14359a1"),
|
|
};
|
|
|
|
/// <summary>
|
|
/// 发送异常信息
|
|
/// </summary>
|
|
/// <param name="exp">异常</param>
|
|
/// <param name="expSrc">异常来源(用于显示)</param>
|
|
/// <returns></returns>
|
|
public static async Task<bool> 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;
|
|
|
|
}
|
|
|
|
}
|
|
}
|