ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 1、写系统错误日志(方便调试) ``` /// <summary> /// 日志部分(为方便技术人员调试) /// </summary> /// <param name="folder">文件夹</param> /// <param name="type">操作类型</param> /// <param name="content">内容</param> public static void WriteLogsE(string folder, string type, string content) { string path = AppDomain.CurrentDomain.BaseDirectory; if (!string.IsNullOrEmpty(path)) { path = AppDomain.CurrentDomain.BaseDirectory + folder; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = path + "\\" + DateTime.Now.ToString("yyyyMMdd"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = path + "\\" + DateTime.Now.ToString("HH") + ".txt"; if (!File.Exists(path)) { FileStream fs = File.Create(path); fs.Close(); } if (File.Exists(path)) { StreamWriter sw = new StreamWriter(path, true, System.Text.Encoding.Default); sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " >> " + type + " >> " + content); sw.WriteLine("-----------------------------------------------------------"); sw.Close(); } } } ``` ## 使用 ``` try { aliyunsms a = new aliyunsms(); string c=a.send("13700605160", "777", "999"); LogsHelper.WriteLogsE("log", "发送短信", c); } catch (Exception err) { LogsHelper.WriteLogsE("log", "发短信错误", err.Message); throw; } ``` ## 使用效果 系统会在当前目录下建目录 并写错误信息 ``` 2018-09-27 17:34:44.049 >> 用户登录 >> Specified signature is not matched with our calculation. server string to sign is:GET&%2F&AccessKeyId%3DLTAIqVC3UPyCJaKB%26Action%3DSendSms%26Format%3DJSON%26OutId%3Dok%26PhoneNumbers%3D13700605160%26RegionId%3Dcn-hangzhou%26SignName%3D%25E4%25B8%25AD%25E5%259B%25BD%25E7%25BF%25BC%25E9%2580%259A%26SignatureMethod%3DHMAC-SHA1%26SignatureNonce%3Db59c5d45-5d85-4138-a1ec-023f2596d515%26SignatureVersion%3D1.0%26TemplateCode%3D777%26TemplateParam%3D999%26Timestamp%3D2018-09-27T09%253A34%253A43Z%26Version%3D2017-05-25 ----------------------------------------------------------- 2018-09-27 17:36:02.382 >> 发送短信 >> Specified signature is not matched with our calculation. server string to sign is:GET&%2F&AccessKeyId%3DLTAIqVC3UPyCJaKB%26Action%3DSendSms%26Format%3DJSON%26OutId%3Dok%26PhoneNumbers%3D13700605160%26RegionId%3Dcn-hangzhou%26SignName%3D%25E4%25B8%25AD%25E5%259B%25BD%25E7%25BF%25BC%25E9%2580%259A%26SignatureMethod%3DHMAC-SHA1%26SignatureNonce%3D2245e9a6-1382-46d2-8fcd-8d67eec86e03%26SignatureVersion%3D1.0%26TemplateCode%3D777%26TemplateParam%3D999%26Timestamp%3D2018-09-27T09%253A36%253A01Z%26Version%3D2017-05-25 ----------------------------------------------------------- 2018-09-27 17:36:42.228 >> 发送短信 >> JSON参数不合法 ----------------------------------------------------------- 2018-09-27 17:36:58.656 >> 发送短信 >> JSON参数不合法 ----------------------------------------------------------- 2018-09-27 17:36:59.323 >> 发送短信 >> JSON参数不合法 ----------------------------------------------------------- 2018-09-27 17:36:59.931 >> 发送短信 >> JSON参数不合法 ----------------------------------------------------------- 2018-09-27 17:37:00.504 >> 发送短信 >> JSON参数不合法 ----------------------------------------------------------- 2018-09-27 17:37:01.074 >> 发送短信 >> JSON参数不合法 ----------------------------------------------------------- ```