/** * @ 写入日志到服务器 * @ url 服务器地址 * @ text 日志文本 * @ type 日志类型 * @ ex 异常信息,如果有 * */ private void WriteToServer(string url, string text, LogType type = LogType.INFO, Exception ex = null) { lock (RemoteLock) { try { Uri uri = new Uri(url); string Parameter = string.Format("text={0}&type={1}", text, type.ToInt()); if (ex != null) { Parameter = string.Format("{0}&exp={1}{2}", Parameter, ex.Message, ex.StackTrace); } byte[] datas = Encoding.UTF8.GetBytes(Parameter); HttpClient client = new HttpClient(); ByteArrayContent content = new ByteArrayContent(datas, 0, datas.Length); client.PostAsync(url, content); } catch { } } }
/** * @ 写入日志到服务器 * @ url 服务器地址 * @ text 日志文本 * @ type 日志类型 * @ ex 异常信息,如果有 * */ private static void WrteToServer(string url, string text, LogType type = LogType.INFO, Exception ex = null) { lock (RemoteLock) { try { Uri uri = new Uri(url); string Parameter = string.Format("text={0}&type={1}", text, type.ToInt()); if (ex != null) { Parameter = string.Format("{0}&exp={1}{2}", Parameter, ex.Message, ex.StackTrace); } byte[] datas = Encoding.UTF8.GetBytes(Parameter); using (WebClient client = new WebClient()) { client.UploadData(uri, "POST", datas); } } catch { } } }