public void SimpleWriteClipboardData() { TextLogger logger = new TextLogger(); logger.Write("Foo"); logger.GetClipboardData().Data.Should().Be("Foo"); }
private void Send(object email) { try { SmtpClient smtpClient = new SmtpClient(SmtpServer); smtpClient.UseDefaultCredentials = false; smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpClient.Credentials = new NetworkCredential(Accounts, Password); SmtpClient smtpClient2 = smtpClient; MailMessage mailMessage = new MailMessage(SmtpSenderEmail, email.ToString(), Subject, Content); mailMessage.IsBodyHtml = true; mailMessage.BodyEncoding = Encoding.GetEncoding("gb2312"); MailMessage mailMessage2 = mailMessage; if (Port != 25) { smtpClient2.EnableSsl = true; } smtpClient2.Send(mailMessage2); mailMessage2.Dispose(); } catch (Exception ex) { TextLogger.Write(ex.ToString()); } }
private void Application_OnError(object sender, EventArgs e) { HttpApplication httpApplication = (HttpApplication)sender; HttpContext context = httpApplication.Context; Exception ex = context.Server.GetLastError(); if (ex is HttpException) { HttpException ex2 = ex as HttpException; if (ex2.GetHttpCode() == 404) { string physicalPath = httpApplication.Request.PhysicalPath; TextLogger.Write(string.Format("文件不存在:{0}", httpApplication.Request.Url.AbsoluteUri)); return; } } if (ex.InnerException != null) { ex = ex.InnerException; } StringBuilder stringBuilder = new StringBuilder().AppendFormat("访问路径:{0}", GameRequest.GetRawUrl()).AppendLine().AppendFormat("{0} thrown {1}", ex.Source, ex.GetType().ToString()) .AppendLine() .Append(ex.Message) .Append(ex.StackTrace); TextLogger.Write(stringBuilder.ToString()); }
public void SimpleUnderline() { TextLogger logger = new TextLogger(); logger.Write(WriteStyle.Underline, "Foo"); logger.ToString().Should().Be("Foo\r\n---"); }
public void SimpleWrite() { TextLogger logger = new TextLogger(); logger.Write("Foo"); logger.ToString().Should().Be("Foo"); }
private void Send(object email) { try { SmtpClient smtpClient = new SmtpClient(this.SmtpServer) { UseDefaultCredentials = false, DeliveryMethod = SmtpDeliveryMethod.Network, Credentials = new NetworkCredential(this.Accounts, this.Password) }; MailMessage mailMessage = new MailMessage(this.SmtpSenderEmail, email.ToString(), this.Subject, this.Content) { IsBodyHtml = true, BodyEncoding = System.Text.Encoding.GetEncoding("gb2312") }; if (this.Port != 25) { smtpClient.EnableSsl = true; } smtpClient.Send(mailMessage); mailMessage.Dispose(); } catch (System.Exception ex) { TextLogger.Write(ex.ToString()); } }
public void Test2() { var now = new DateTime(2015, 2, 1); StreamTextWriterFactory writerFactory = new StreamTextWriterFactory(new DayLogPathFactory()); TextLogger logger = new TextLogger(writerFactory, new LogDescriptor()); writerFactory.NowGetter = () => now; logger.Write(new LogItem() { Time = now, Message = "测试内容。", Type = LogType.Info }); System.Threading.Thread.Sleep(1001); var path = GA.FullPath(LogFolder, "2015年02月", "01.log"); try { Assert.Equal(now.ToString("HH:mm:ss.ffff") + " [消息] 测试内容。\r\n", GA.IO.ShareReadAllText(path, Encoding.UTF8)); } catch (UnauthorizedAccessException) { //.... } }
public void Test2() { var now = new DateTime(2015, 2, 1); StreamTextWriterFactory writerFactory = new StreamTextWriterFactory(new DayLogPathFactory()); TextLogger logger = new TextLogger(writerFactory, new LogDescriptor()); writerFactory.NowGetter = () => now; logger.Write(new LogItem() { Time = now, Message = "测试内容。", Type = LogType.Info }); System.Threading.Thread.Sleep(1001); var path = GA.FullPath(LogFolder, "2015年02月", "01.log"); Assert.Equal(now.ToString("HH:mm:ss.ffff") + " [消息] 测试内容。\r\n", GA.IO.ShareReadAllText(path, Encoding.UTF8)); }
/// <summary> /// 发送推送信息 /// </summary> /// <param name="DeviceType">设备类型(0 表示android 1 表示IOS )</param> /// <param name="Text">推送信息内容</param> /// <param name="SendType">消息类型(unicast 单播 broadcast 广播 listcast-列播)</param> /// <param name="token">设备唯一标识(当类型为unicast时必须填写)</param> public static bool SendMessage(int DeviceType, string Text, string SendType, string startTime, string endTime, string token = "") { try { //获取时间戳 string timestamp = GetTimeStamp(); //数据签名 string mysign = string.Empty; //参数集合 StringBuilder sb = new StringBuilder(); if (DeviceType == 1) { //苹果参数集合体 sb.Append("{"); sb.AppendFormat("\"appkey\":\"{0}\",", AppKey_IOS); sb.AppendFormat("\"timestamp\":{0},", timestamp); sb.AppendFormat("\"type\":\"{0}\",", SendType); if (SendType != "broadcast") { sb.AppendFormat("\"device_tokens\":\"{0}\",", token); } sb.Append("\"payload\":{"); sb.Append("\"aps\":{"); sb.AppendFormat("\"alert\":\"{0}\"", Text); sb.Append("}"); sb.Append("},"); sb.Append("\"policy\":{"); sb.AppendFormat("\"start_time\":\"{0}\",", startTime); sb.AppendFormat("\"expire_time\":\"{0}\",", endTime); sb.Append("},"); sb.AppendFormat("\"production_mode\":\"{0}\",", UmengProductionMode); sb.AppendFormat("\"description\":\"{0}\"", Text); sb.Append("}"); mysign = GetMD5("POST" + AppUrl + sb.ToString() + AppSecret_IOS); } else { //安卓参数集合体 sb.Append("{"); sb.AppendFormat("\"appkey\":\"{0}\",", AppKey_Android); sb.AppendFormat("\"timestamp\":{0},", timestamp); sb.AppendFormat("\"type\":\"{0}\",", SendType); if (SendType != "broadcast") { sb.AppendFormat("\"device_tokens\":\"{0}\",", token); } sb.Append("\"payload\":{"); sb.AppendFormat("\"display_type\":\"{0}\",", "notification"); sb.Append("\"body\":{"); sb.AppendFormat("\"ticker\":\"{0}\",", Text); sb.AppendFormat("\"title\":\"{0}\",", Text); sb.AppendFormat("\"text\":\"{0}\",", Text); sb.AppendFormat("\"after_open\":\"{0}\"", "go_app"); sb.Append("}"); sb.Append("},"); sb.Append("\"policy\":{"); sb.AppendFormat("\"start_time\":\"{0}\",", startTime); sb.AppendFormat("\"expire_time\":\"{0}\",", endTime); sb.Append("},"); sb.AppendFormat("\"production_mode\":\"{0}\",", UmengProductionMode); sb.AppendFormat("\"description\":\"{0}\"", Text); sb.Append("}"); mysign = GetMD5("POST" + AppUrl + sb.ToString() + AppSecret_Android); } //请求接口地址 string requestUrl = AppUrl + "?sign=" + mysign; TextLogger.Write("UMeng RequestUrl:" + requestUrl + " sb:" + sb.ToString()); HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest; request.Method = "POST"; byte[] bs = Encoding.UTF8.GetBytes(sb.ToString()); request.ContentLength = bs.Length; using (Stream reqStream = request.GetRequestStream()) { reqStream.Write(bs, 0, bs.Length); reqStream.Close(); } HttpWebResponse response = (HttpWebResponse)request.GetResponse(); HttpStatusCode statusCode = response.StatusCode; TextLogger.Write("UMeng Response:" + response.StatusCode); return(true); } catch (WebException e) { if (e.Status == WebExceptionStatus.ProtocolError) { HttpStatusCode code = ((HttpWebResponse)e.Response).StatusCode; string descript = ((HttpWebResponse)e.Response).StatusDescription; Stream myResponseStream = ((HttpWebResponse)e.Response).GetResponseStream(); StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8")); string retString = myStreamReader.ReadToEnd(); TextLogger.Write("UMeng Response:" + retString); } return(false); } }
private void SetupLogger() { TextLogger = new TextLogger(); TextLogger.NewLogMessage += () => RaisePropertyChanged("TextLogger"); TextLogger.Write(Logger.MessageType.Info, "Welcome to the Delta Engine Editor"); }
/// <summary> /// Sends an informational message to the log /// </summary> /// <param name="message">Message to log</param> public static void Log(object message) => Logger.Write(FormatMessage(message.ToString(), "INFO"));
private void TryLogInfoToLogOutput(string logMessage) { TextLogger = new TextLogger(); TextLogger.Write(Logger.MessageType.Info, logMessage); }