/// <summary> /// Convenience method for easily formatting the logging event into a string variable. /// </summary> /// <param name="loggingEvent"></param> /// <remarks> /// Creates a new StringWriter instance to store the formatted logging event. /// </remarks> public string Format(LoggingData loggingEvent) { StringWriter writer = new StringWriter(System.Globalization.CultureInfo.InvariantCulture); Format(writer, loggingEvent); return(writer.ToString()); }
private static void DebugWrite(string message, LoggingData data) { foreach (string msg in data.ToStrings()) { System.Diagnostics.Debug.WriteLine(message + " " + msg); } }
/// <summary> /// Deliver the <see cref="LoggingData"/> to the attached appenders. /// </summary> /// <param name="loggingEvent">The event to log.</param> /// <remarks> /// <para> /// Call the appenders in the hierarchy starting at /// <c>this</c>. If no appenders could be found, emit a /// warning. /// </para> /// <para> /// This method calls all the appenders inherited from the /// hierarchy circumventing any evaluation of whether to log or not /// to log the particular log request. /// </para> /// </remarks> virtual protected void CallAppenders(LoggingData loggingEvent) { if (loggingEvent == null) { throw new ArgumentNullException("loggingEvent"); } loggingEvent.LoggerName = this.m_name; loggingEvent.TimeStamp = DateTime.Now; loggingEvent.AppNo = m_hierarchy.AppNo; loggingEvent.Unique = Guid.NewGuid().ToString(); loggingEvent.ThreadName = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString(System.Globalization.NumberFormatInfo.InvariantInfo); m_appenderLock.AcquireReaderLock(); try { if (m_appenderAttachedImpl != null) { m_appenderAttachedImpl.AppendLoopOnAppenders(loggingEvent); } } finally { m_appenderLock.ReleaseReaderLock(); } }
/// <summary> /// 保存箱子信息 /// </summary> /// <param name="obj"></param> /// <returns></returns> public bool SaveBox(Box obj) { LoggingData data = new LoggingData(ip, username, password, database); bool result = data.SaveBox(obj.Code, Convert.ToByte(obj.IsIdle), obj.CoordinateInfo.X, obj.CoordinateInfo.Y, obj.RemarkInfo, (byte)obj.ThisSize, (byte)obj.CurrentState); return(result); }
/// <summary> /// Format the logging event as an object. /// </summary> /// <param name="loggingEvent">The event to format</param> /// <returns>returns the formatted event</returns> /// <remarks> /// <para> /// Format the logging event as an object. /// </para> /// <para> /// Uses the <see cref="ILayout"/> object supplied to /// the constructor to perform the formatting. /// </para> /// </remarks> virtual public object Format(LoggingData loggingEvent) { StringWriter writer = new StringWriter(System.Globalization.CultureInfo.InvariantCulture); m_layout.Format(writer, loggingEvent); return(writer.ToString()); }
private bool SendSMS(string Number, string Content, byte dcs) { try { SmsSubmitPdu sms = new SmsSubmitPdu(Content, Number, dcs); string pdu = sms.ToString(false); string response = ExecuteCommands("AT+CMGS=" + sms.ActualLength.ToString() + "", 1000); if (!CheckNEXT(response)) { LoggingData.WriteLog("Send SMS failed. GSM Modem does not respond to commands"); return(false); } response = ExecuteCommands(pdu + char.ConvertFromUtf32(26), 10000); if (!CheckOK(response)) { LoggingData.WriteLog("Send SMS failed. GSM Modem does not respond to commands"); return(false); } ; return(true); } catch (Exception ex) { LoggingData.WriteLog(ex); return(false); } }
public bool OpenPort(bool ResetConfig = false) { try { if (ResetConfig) { if (SpGSM_Modem != null && SpGSM_Modem.IsOpen) { SpGSM_Modem.Close(); } SpGSM_Modem.PortName = this.PortName; SpGSM_Modem.Open(); return(SpGSM_Modem.IsOpen); } else { if (!SpGSM_Modem.IsOpen) { SpGSM_Modem.Open(); } return(SpGSM_Modem.IsOpen); } } catch (Exception ex) { LoggingData.WriteLog(ex); return(false); } }
public string WaitingData(int timeout, string ResultContain = null, string Error = "") { receive_AutoResponse.Reset(); try { string result = ""; do { if (receive_AutoResponse.WaitOne(timeout, false)) { string t = SpGSM_Modem_AutoResponse.ReadExisting(); result += t; } else { string t = SpGSM_Modem_AutoResponse.ReadExisting(); result += t; return(result); } }while ((!result.EndsWith("\r\nOK\r\n") && !result.EndsWith("\r\n> ") && !result.EndsWith("\r\nERROR\r\n") && !result.EndsWith("\r\n") && !result.EndsWith("\r")) && ((ResultContain != null && result.Contains(ResultContain)) || ResultContain == null)); return(result); } catch (Exception ex) { LoggingData.WriteLog(ex); return(string.Empty); } }
public bool OpenModem(out string msg) { try { if (!OpenPort()) { msg = "GSM Modem can not connect. Please check again"; return(false); } else { msg = ""; string response = ExecuteCommands("AT", 1000); if (!CheckOK(response)) { msg = "GSM Modem does not respond to commands. or the device is not a GSM modem"; ClosePort(); return(false); } InitModemConfig(); msg = string.Empty; return(true); } } catch (Exception ex) { LoggingData.WriteLog(ex); msg = "There was an unknown error. Please check and try again"; return(false); } }
private static void ReadProperties(LoggingData logging, XmlReader reader) { reader.MoveToContent(); var properties = new StringDictionary(); while (reader.Read() && reader.NodeType != XmlNodeType.EndElement) { if (!reader.MoveToFirstAttribute()) { reader.MoveToElement(); continue; } var key = reader.Value; if (!reader.MoveToNextAttribute()) { reader.MoveToElement(); continue; } var value = reader.Value; properties.Add(key, value); reader.MoveToElement(); } logging.Properties = properties; reader.ReadEndElement(); }
public string ExecuteCommands(string ATcommand, int timeout, string Error = "") { receiveNow.Reset(); try { string result = ""; SpGSM_Modem.Write(ATcommand + "\r"); do { if (receiveNow.WaitOne(timeout, false)) { string t = SpGSM_Modem.ReadExisting(); result += t; } else { string t = SpGSM_Modem.ReadExisting(); result += t; return(result); } }while (!result.EndsWith("\r\nOK\r\n") && !result.EndsWith("\r\n> ") && !result.EndsWith("\r\nERROR\r\n")); return(result); } catch (Exception ex) { LoggingData.WriteLog(ex); return(ex.Message); } }
private static void ReadException(LoggingData logging, XmlReader reader) { reader.Read(); logging.ExceptionString = reader.Value; reader.Read(); reader.ReadEndElement(); }
/// <summary> /// Append on on all attached appenders. /// </summary> /// <param name="loggingEvent">The event being logged.</param> /// <returns>The number of appenders called.</returns> /// <remarks> /// <para> /// Calls the <see cref="IAppender.DoAppend" /> method on all /// attached appenders. /// </para> /// </remarks> public int AppendLoopOnAppenders(LoggingData loggingEvent) { if (loggingEvent == null) { throw new ArgumentNullException("loggingEvent"); } // m_appenderList is null when empty if (m_AppenderList == null) { return(0); } foreach (IAppender appender in m_AppenderList) { try { appender.DoAppend(loggingEvent); } catch (Exception ex) { LogLog.Error(declaringType, "Failed to append to appender [" + appender.Name + "]", ex); } } return(m_AppenderList.Count); }
/// <summary> /// 随机获取箱子 /// </summary> /// <param name="size"></param> /// <returns></returns> public Box GetIdleBoxBySize(Box.Size size) { DataTable table = null; LoggingData data = new LoggingData(ip, username, password, database); table = data.GetIdleBoxBySize((int)size); if (table == null || table.Rows.Count == 0) { CLog4net.LogError("未找到合适大小箱子:" + size); return(null); } Box cb = new Box(); foreach (System.Data.DataRow d in table.Rows) { cb.Id = Convert.ToInt32(d[TbBox.id]); cb.Code = Convert.ToInt32(d[TbBox.code]); Box.Coordinate location = new Box.Coordinate(); location.X = Convert.ToInt32(d[TbBox.locationX]); location.Y = Convert.ToInt32(d[TbBox.locationY]); cb.CoordinateInfo = location; cb.CurrentState = (Box.State)Convert.ToByte(d[TbBox.state]); cb.IsIdle = Convert.ToBoolean(d[TbBox.idle]); cb.ThisSize = (Box.Size)Convert.ToByte(d[TbBox.size]); cb.RemarkInfo = Convert.ToString(d[TbBox.remark]); } return(cb); }
/// <summary> /// 获取全部箱子 /// </summary> /// <returns></returns> public List <Box> GetBoxs() { DataTable table = null; LoggingData data = new LoggingData(ip, username, password, database); table = data.GetBoxs(); if (table == null) { CLog4net.LogError("柜子表初始化错误"); return(null); } List <Box> boxes = new List <Box>(); foreach (System.Data.DataRow d in table.Rows) { Box cb = new Box(); cb.Id = Convert.ToInt32(d[TbBox.id]); cb.Code = Convert.ToInt32(d[TbBox.code]); Box.Coordinate location = new Box.Coordinate(); location.X = Convert.ToInt32(d[TbBox.locationX]); location.Y = Convert.ToInt32(d[TbBox.locationY]); cb.CoordinateInfo = location; cb.CurrentState = (Box.State)Convert.ToByte(d[TbBox.state]); cb.IsIdle = Convert.ToBoolean(d[TbBox.idle]); cb.ThisSize = (Box.Size)Convert.ToByte(d[TbBox.size]); cb.RemarkInfo = Convert.ToString(d[TbBox.remark]); boxes.Add(cb); } return(boxes); }
/// <summary> /// Logs the specified logging data. /// </summary> /// <param name="loggingData">The logging data.</param> public void Log(LoggingData loggingData) { var logEvent = new LogEventInfo(); logEvent.LoggerName = loggingData.LoggerName; logEvent.Message = loggingData.Message; logEvent.TimeStamp = loggingData.TimeStamp; if (!string.IsNullOrEmpty(loggingData.Exception)) { logEvent.Exception = new Exception(loggingData.Exception); } if (loggingData.Properties != null && loggingData.Properties.Count > 0) { var properties = loggingData.Properties; var dict = new Dictionary <object, object>(); foreach (var k in properties.Keys.OfType <string>()) { properties.Add(k, properties[k]); } } logger.Log(logEvent); }
public List <ELock> GetELock() { DataTable table = null; LoggingData data = new LoggingData(ip, username, password, database); table = data.GetELock(); if (table == null) { CLog4net.LogError("锁控板列表初始化错误"); return(null); } List <ELock> boxes = new List <ELock>(); foreach (System.Data.DataRow d in table.Rows) { ELock cb = new ELock(); cb.Id = Convert.ToInt32(d[TbELock.id]); if (d[TbELock.boxCode].ToString() != "") { cb.BoxCode = Convert.ToInt32(d[TbELock.boxCode]); } cb.Address = Convert.ToString(d[TbELock.ip]); cb.Password = Convert.ToString(d[TbELock.password]); cb.Value = Convert.ToString(d[TbELock.value]); boxes.Add(cb); } return(boxes); }
public byte[] SendData(byte[] data, int timeoutSend = 60000, int timeoutRecv = 60000) { try { if (client != null && client.IsConnected()) { RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(); byte[] dataEncrypt = CommonFunctions.Encryption(data, RSA.ExportParameters(false), false); sendDone.Reset(); receiveDone.Reset(); client.BeginSend(dataEncrypt, 0, dataEncrypt.Length, 0, new AsyncCallback(SendCallback), client); sendDone.WaitOne(timeoutSend); StateObject state = new StateObject(); state.workSocket = client; client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), state); receiveDone.WaitOne(timeoutRecv); return(responseServerData); } return(null); } catch (Exception ex) { LoggingData.WriteLog(ex); Console.WriteLine(ex.ToString()); return(null); } }
public bool DeletePackage(Package obj) { LoggingData data = new LoggingData(ip, username, password, database); bool result = data.DeletePackage(obj.SN); return(result); }
public bool UpdatePickUpLog(PickUpLog obj) { LoggingData data = new LoggingData(ip, username, password, database); bool result = data.UpdatePickUpLog(obj.Id, obj.Sn, obj.CourierCode, obj.ReceiverTelNum, obj.BoxCode, obj.DeletedTime, obj.ReceiverIdentity, Convert.ToByte(obj.ServerSaved), obj.Remark); return(result); }
public List <PickUpLog> GetPickUpLogNoUpload() { DataTable table = null; LoggingData data = new LoggingData(ip, username, password, database); table = data.GetPickUpLogNoUpload(); if (table == null) { CLog4net.LogError("取件日志表初始化错误"); return(null); } List <PickUpLog> a = new List <PickUpLog>(); foreach (System.Data.DataRow d in table.Rows) { PickUpLog pl = new PickUpLog(); pl.Sn = Convert.ToString(d[TbPickuplog.packageCode]); pl.CourierCode = Convert.ToString(d[TbPickuplog.courierCode]); pl.ReceiverTelNum = Convert.ToString(d[TbPickuplog.receiverTelNum]); pl.BoxCode = Convert.ToInt32(d[TbPickuplog.boxCode]); pl.DeletedTime = Convert.ToDateTime(d[TbPickuplog.deletedTime]); pl.ReceiverIdentity = Convert.ToByte(d[TbPickuplog.receiverIdentity]); pl.ServerSaved = Convert.ToBoolean(d[TbPickuplog.serverSaved]); pl.Remark = Convert.ToString(d[TbPickuplog.remark]); a.Add(pl); } return(a); }
public bool UpdatePackage(Package obj) { LoggingData data = new LoggingData(ip, username, password, database); bool result = data.UpdatePackage(obj.SN, obj.Courier.Code, obj.ReceiverTelNum, obj.Place.Code, Convert.ToByte(obj.Taken), obj.CreatedTime, obj.DeletedTime, obj.ReceiverIdentity, obj.RemarkInfo); return(result); }
public bool UpdateAboutPassword(string password) { LoggingData data = new LoggingData(ip, username, password, database); bool result = data.UpdateAbout(password); return(result); }
public List <DeliverLog> GetDeliverLogNoUpload() { DataTable table = null; LoggingData data = new LoggingData(ip, username, password, database); table = data.GetDeliverLogNoUpload(); if (table == null) { CLog4net.LogError("寄件日志表初始化错误"); return(null); } List <DeliverLog> a = new List <DeliverLog>(); foreach (System.Data.DataRow d in table.Rows) { DeliverLog dl = new DeliverLog(); dl.Sn = Convert.ToString(d[TbDeliverLog.packageCode]); dl.CourierCode = Convert.ToString(d[TbDeliverLog.courierCode]); dl.ReceiverTelNum = Convert.ToString(d[TbDeliverLog.receiverTelNum]); dl.BoxCode = Convert.ToInt32(d[TbDeliverLog.boxCode]); dl.CreatedTime = Convert.ToDateTime(d[TbDeliverLog.createdTime]); dl.ServerSaved = Convert.ToBoolean(d[TbDeliverLog.serverSaved]); dl.Remark = Convert.ToString(d[TbDeliverLog.remark]); a.Add(dl); } return(a); }
public About GetAbout() { DataTable table = null; LoggingData data = new LoggingData(ip, username, password, database); table = data.GetAbout(); if (table == null) { CLog4net.LogError("快递表初始化错误"); return(null); } About a = new About(); foreach (System.Data.DataRow d in table.Rows) { /** * 从数据库中读取未被取走的快递 * */ a.Address = Convert.ToString(d[TbAbout.address]); a.CabinetCode = Convert.ToString(d[TbAbout.cabinetCode]); a.CompanyName = Convert.ToString(d[TbAbout.companyName]); a.ConfigTime = Convert.ToDateTime(d[TbAbout.configTime]); a.CreatedTime = Convert.ToDateTime(d[TbAbout.createdTime]); a.Name = Convert.ToString(d[TbAbout.name]); a.Remark = Convert.ToString(d[TbAbout.remark]); a.TelNum = Convert.ToString(d[TbAbout.telNum]); a.Version = Convert.ToString(d[TbAbout.version]); a.ServerUrl = Convert.ToString(d[TbAbout.serverUrl]); a.ManagerName = Convert.ToString(d[TbAbout.managerName]); a.ManagerPassword = Convert.ToString(d[TbAbout.managerPassword]); a.Model = Convert.ToString(d[TbAbout.model]); } return(a); }
public bool SaveDeliverLog(Resource.DeliverLog obj) { LoggingData data = new LoggingData(ip, username, password, database); bool result = data.SaveDeliverLog(obj.Sn, obj.CourierCode, obj.ReceiverTelNum, obj.BoxCode, obj.CreatedTime, Convert.ToByte(obj.ServerSaved), obj.Remark); return(result); }
protected override void Prepare(LoggingData logging) { if (logging.Properties != null) { logging.ApplicationName = logging.Properties["log4japp"]; } }
/// <summary> /// ログにメッセージを書き込みます。 /// </summary> /// <param name="messages">メッセージリスト</param> /// <param name="type">ログタイプ</param> public static void Write(List <string> messages, LogTypes type = LogTypes.Information) { LoggingData data = new LoggingData(Internal.DateTime.Now, type, messages); DebugWrite(data); loggingBuffer.Enqueue(data); WriteLogFileAsync(); }
/// <summary> /// Log the logEvent through this hierarchy. /// </summary> /// <param name="logEvent">the event to log</param> /// <remarks> /// <para> /// This method should not normally be used to log. /// The <see cref="ILog"/> interface should be used /// for routine logging. This interface can be obtained /// using the <see cref="M:log4net.LogManager.GetLogger(string)"/> method. /// </para> /// <para> /// The <c>logEvent</c> is delivered to the appropriate logger and /// that logger is then responsible for logging the event. /// </para> /// </remarks> override public void Log(LoggingData logEvent) { if (logEvent == null) { throw new ArgumentNullException("logEvent"); } this.GetLogger(logEvent.LoggerName, m_defaultFactory).Log(logEvent); }
/// <summary> /// Renders the <see cref="LoggingData"/> to a string. /// </summary> /// <param name="loggingEvent">The event to render.</param> /// <param name="writer">The TextWriter to write the formatted event to</param> /// <remarks> /// <para> /// Helper method to render a <see cref="LoggingData"/> to /// a string. This appender must have a <see cref="Layout"/> /// set to render the <paramref name="loggingEvent"/> to /// a string. /// </para> /// <para>If there is exception data in the logging event and /// the layout does not process the exception, this method /// will append the exception text to the rendered string. /// </para> /// <para> /// Use this method in preference to <see cref="M:RenderLoggingEvent(LoggingEvent)"/> /// where possible. If, however, the caller needs to render the event /// to a string then <see cref="M:RenderLoggingEvent(LoggingEvent)"/> does /// provide an efficient mechanism for doing so. /// </para> /// </remarks> protected void RenderLoggingEvent(TextWriter writer, LoggingData loggingEvent) { if (m_layout == null) { throw new InvalidOperationException("A layout must be set"); } // The layout will render the exception m_layout.Format(writer, loggingEvent); }
public ConstantObjectLoggingDataExtractor(LoggingData[] constant) { this.constant = constant; }
public string Log(LoggingData data) { return "Plain"; }
public void Log(LoggingData loggingData) { var logEvent = new LogEventInfo(); logEvent.LoggerName = loggingData.LoggerName; logEvent.Message = loggingData.Message; logEvent.TimeStamp = loggingData.TimeStamp; if (!string.IsNullOrEmpty(loggingData.ExceptionString)) logEvent.Exception = new Exception(loggingData.ExceptionString); if (loggingData.Properties != null && loggingData.Properties.Count > 0) { var properties = loggingData.Properties; var dict = new Dictionary<object, object>(); foreach(var k in properties.Keys.OfType<string>()) { properties.Add(k, properties[k]); } } if(loggingData.LocationInfo != null) { var locationInfo = loggingData.LocationInfo; var lineNumber = 0; int.TryParse(locationInfo.LineNumber, out lineNumber); logEvent.SetStackTrace(new StackTrace(new StackFrame(locationInfo.FileName, lineNumber)), 0); } LogLevel level; if (!s_LevelDict.TryGetValue(loggingData.Level, out level)) level = LogLevel.Info; logEvent.Level = level; m_Logger.Log(logEvent); }
public string Log(LoggingData data) { return "Custom"; }
/// <summary> /// Logs the specified logging data. /// </summary> /// <param name="loggingData">The logging data.</param> /// <exception cref="System.NotSupportedException"></exception> public void Log(LoggingData loggingData) { var loggingEventData = new LoggingEventData(); loggingEventData.Domain = loggingData.Domain; loggingEventData.ExceptionString = loggingData.ExceptionString; loggingEventData.LoggerName = loggingData.LoggerName; loggingEventData.Level = s_LevelDict[loggingData.Level]; loggingEventData.Message = loggingData.Message; loggingEventData.ThreadName = loggingData.ThreadName; loggingEventData.TimeStamp = loggingData.TimeStamp; loggingEventData.UserName = loggingData.UserName; m_Log.Logger.Log(new LoggingEvent(loggingEventData)); }
public string Log(LoggingData data) { return "Ninject"; }