private void setSystemEvent() { try { string subject = BCAppConstants.NATSTopics.NATS_SUBJECT_SYSTEM_LOG; //指定要執行的動作 EventHandler <StanMsgHandlerArgs> msgHandler = (senders, args) => { lock (systemEventLock) { byte[] arrayByte = args.Message.Data; if (arrayByte == null) { return; } //反序列化 Google.Protobuf.MessageParser <SYSTEMPROCESS_INFO> parser = new Google.Protobuf.MessageParser <SYSTEMPROCESS_INFO>(() => new SYSTEMPROCESS_INFO()); SYSTEMPROCESS_INFO systemEventInfo = parser.ParseFrom(arrayByte); if (systemProcLst.Count > MAX_LOG_MSG_COUNT) { systemProcLst.RemoveAt(systemProcLst.Count - 1); } systemProcLst.Insert(0, systemEventInfo); //更新畫面 Adapter.Invoke(new SendOrPostCallback((o1) => { //dgv_systemLog.DataSource = systemProcLst; uc_grid_SystemLog1.grid_Sys_Log.ItemsSource = systemProcLst; }), null); } }; //訂閱 app.GetNatsManager().Subscriber(subject, msgHandler, false, true, 0, null); //當subject有變化,則進行msgHandler的動作 } catch (Exception ex) { logger.Error(ex, "Exception"); } }
public void PublishSystemMsgInfo(Object systemLog) { lock (publishSystemMsgLock) { try { SYSTEMPROCESS_INFO logObj = systemLog as SYSTEMPROCESS_INFO; byte[] systemMsg_Serialize = BLL.LineBLL.Convert2GPB_SystemMsgInfo(logObj); if (systemMsg_Serialize != null) { scApp.getNatsManager().PublishAsync (SCAppConstants.NATS_SUBJECT_SYSTEM_LOG, systemMsg_Serialize); } } catch (Exception ex) { logger.Error(ex, "Exception:"); } } }
public static void Log(Logger logger, NLog.LogLevel LogLevel, string Class, string Device, string Data = "", string VehicleID = null, string CarrierID = null, LogConstants.Type?Type = null, string LogID = null, string Level = null, string ThreadID = null, string Lot = null, string XID = null, string Details = null, [CallerMemberName] string Method = "") { LogObj logObj = LogObjPool.GetObject(); try { logObj.dateTime = DateTime.Now; logObj.Sequence = getSequence(); logObj.LogLevel = LogLevel.Name; logObj.Class = Class; logObj.Method = Method; logObj.Device = Device; logObj.Data = Data; logObj.VH_ID = VehicleID; logObj.CarrierID = CarrierID; logObj.Type = Type; logObj.LogID = LogID; logObj.ThreadID = ThreadID != null ? ThreadID : Thread.CurrentThread.ManagedThreadId.ToString(); logObj.Lot = Lot; logObj.Level = Level; string service_id = System.Runtime.Remoting.Messaging.CallContext.GetData(CALL_CONTEXT_KEY_WORD_SERVICE_ID) as string; logObj.ServiceID = service_id; logObj.XID = XID; Transaction Transaction = getCurrentTransaction(); logObj.TransactionID = Transaction == null ? string.Empty : Transaction.TransactionInformation.LocalIdentifier.ToString(); logObj.Details = Details; logObj.Index = "SystemProcessLog"; LogHelper.logger.Log(LogLevel, logObj.ToString()); //Task.Run(() => SCApplication.getInstance().LineService.PublishSystemLog(logObj)); SYSTEMPROCESS_INFO systemProc = new SYSTEMPROCESS_INFO(); systemProc.TIME = DateTime.Now.ToString(SCAppConstants.DateTimeFormat_23); systemProc.SEQ = logObj.Sequence; systemProc.LOGLEVEL = LogLevel.Name == null ? string.Empty : LogLevel.Name; systemProc.CLASS = Class == null ? string.Empty : Class; systemProc.METHOD = Method == null ? string.Empty : Method; systemProc.DEVICE = Device == null ? string.Empty : Device; systemProc.DATA = Data == null ? string.Empty : Data; systemProc.VHID = VehicleID == null ? string.Empty : VehicleID; systemProc.CRRID = CarrierID == null ? string.Empty : CarrierID; systemProc.TYPE = Type.ToString(); systemProc.LOGID = LogID == null ? string.Empty : LogID; systemProc.THREADID = logObj.ThreadID; systemProc.LOT = Lot == null ? string.Empty : Lot; systemProc.LEVEL = Level == null ? string.Empty : Level; systemProc.XID = XID == null ? string.Empty : XID; systemProc.TRXID = logObj.TransactionID; systemProc.DETAILS = Details == null ? string.Empty : Details; System.Threading.ThreadPool.QueueUserWorkItem(new WaitCallback(SCApplication.getInstance().LineService.PublishSystemMsgInfo), systemProc); } catch (Exception e) { LogHelper.logger.Error($"{e}, Exception"); } finally { LogObjPool.PutObject(logObj); } }