Esempio n. 1
0
        public static void WriteTextLog(string log)
        {
            string filename = string.Format(LogFilePath, LogMessageDAL.GetLogTableSuffix());

            try
            {
                lock (m_lockLogFileObj1)
                {
                    if (!File.Exists(filename))
                    {
                        string dirPath = filename.Remove(filename.LastIndexOf("\\") + 1);
                        if (!Directory.Exists(dirPath))
                        {
                            Directory.CreateDirectory(dirPath);
                        }
                    }
                    File.AppendAllText(filename, string.Format(@"-----------------------------------------{1}-----------------------------------------{0}{2}{0}", Environment.NewLine, DateTime.Now.ToString(), log));
                }
            }
            catch { }
        }
Esempio n. 2
0
        private int Insert(LogMessage log)
        {
            int    ret       = 0;
            string tableName = "";

            try
            {
                tableName = "dbo.tbl_Interface_ProcessLog";
                if (log.IsHandle)
                {
                    tableName = "dbo.tbl_Interface_HandleLog";
                }
                tableName = string.Format("{0}{1}", tableName, LogMessageDAL.GetLogTableSuffix());
                string sql = string.Format(@"insert into {0}(IKey, Username, LogTime, ClientIP, ServerIP, Module, Keyword, OrderNo, LogType, Content) 
                    values (@IKey, @Username, @LogTime, @ClientIP, @ServerIP, @Module, @Keyword, @OrderNo, @LogType, @Content)", tableName);

                List <DbParameter> paraList = new List <DbParameter>();
                AddParameter(paraList, "@IKey", log.Ikey);
                AddParameter(paraList, "@Username", log.Username);
                AddParameter(paraList, "@LogTime", log.LogTime);
                AddParameter(paraList, "@ClientIP", log.ClientIP);
                AddParameter(paraList, "@ServerIP", log.ServerIP);
                AddParameter(paraList, "@Module", log.Module);
                AddParameter(paraList, "@Keyword", log.Keyword);
                AddParameter(paraList, "@OrderNo", log.OrderNo);
                AddParameter(paraList, "@LogType", log.LogType);
                AddParameter(paraList, "@Content", log.Content);

                ret = DbHelper.ExecuteNonQuery(DatabaseEnum.Log4Net_CMD, CommandType.Text, sql, paraList.ToArray());
            }
            catch (Exception ex)
            {
                //丢弃日志
                Logger.Fatal(string.Format("往{0}表插入数据出现严重错误,{1}", tableName, log.ToString()), ex);
            }
            return(ret);
        }
Esempio n. 3
0
        private void OnMessageReceived(object sender, ReceiveCompletedEventArgs objArgs)
        {
            try
            {
                Message objRawMsg = m_objMsmq2Listen.EndReceive(objArgs.AsyncResult);

                //改为同步方式
                m_objSubscriberMethod(objRawMsg);

                objRawMsg.Dispose();
                objRawMsg = null;
            }
            catch (Exception ex)
            {
                Logger.Error("接收消息发生异常:" + LogMessageDAL.GetString(ex));
            }
            finally
            {
                if (m_blnRunning)
                {
                    m_objMsmq2Listen.BeginReceive();
                }
            }
        }
Esempio n. 4
0
 public void LogMessage(object obj)
 {
     LogMessageDAL.GetInstance().Insert(obj);
 }
Esempio n. 5
0
        //分布式批量提交数据到远程
        /// <summary>
        /// 分布式批量提交数据到远程
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="isHandle"></param>
        private static void BatchSendRequest(object obj, bool isHandle)
        {
            //获取日志实体列表
            IDataBuffer buffer = obj as IDataBuffer;

            if (buffer == null)
            {
                return;
            }
            List <LogMessage> logMessageList = buffer.GetList <LogMessage>();

            if (logMessageList == null)
            {
                return;
            }

            if (m_openLogCenter)
            {
#if THRIFT
                try
                {
                    SyncLogServerEvent.WaitOne();
                    SendRequestToNewLogCenter(logMessageList);
                    if (logMessageList.Count > 1 && DateTime.Now > lastExecuteLogTime.AddMinutes(5))
                    {
                        lastExecuteLogTime = DateTime.Now;
                        string content = string.Format("本次批量插入{0}条数据,结果:{1},IsHandle:{2}", logMessageList.Count, "Success", isHandle);
                        RecordLogCenterState("分布式日志2.0", content, isHandle, true);
                    }
                    AppMetricsKeys.LogCenterClient.MeterMark(MetricsEnum.Success.ToString(), new string[] { string.Format("Client={0}", MetricsTagEnum.V2.ToString()) });
                    return;
                }
                catch (Exception ex)
                {
                    AppMetricsKeys.LogCenterClient.MeterMark(MetricsEnum.Failed.ToString(), new string[] { string.Format("Client={0}", MetricsTagEnum.V2.ToString()) });
                    m_localLog.Error(ex);
                    string content = string.Format("批量插入数据异常,原因:{0},IsHandle:{1}", ex.ToString(), isHandle);
                    RecordLogCenterState("分布式日志2.0", content, isHandle, false);
                }
#endif
            }
            else
            {
                try
                {
                    LogMessageTaskInfo taskInfo = new LogMessageTaskInfo
                    {
                        CurrLogMessageObj = logMessageList,
                        TaskCreateTime    = DateTime.Now,
                        TaskName          = "LogMessage",
                        EmitServerCode    = m_localServerCode
                    };

                    //发送日志实体列表到远程消息队列
                    ITaskInfo retTask = m_request.SendRequest(m_logToServer, taskInfo);

                    if (logMessageList.Count > 1 &&
                        DateTime.Now > lastExecuteLogTime.AddMinutes(5))
                    {
                        lastExecuteLogTime = DateTime.Now;
                        string content = string.Format("本次批量插入{0}条数据,结果:{1},IsHandle:{2}", logMessageList.Count, retTask.TaskStatus, isHandle);
                        RecordLogCenterState("分布式日志1.0", content, isHandle, retTask.TaskStatus == TaskStatus.Success);
                    }

                    if (retTask.TaskStatus == TaskStatus.Success)
                    {
#if THRIFT
                        AppMetricsKeys.LogCenterClient.MeterMark(MetricsEnum.Success.ToString(), new string[] { string.Format("Client={0}", MetricsTagEnum.V1.ToString()) });
#endif
                        return;
                    }
                }
                catch (Exception ex)
                {
#if THRIFT
                    AppMetricsKeys.LogCenterClient.MeterMark(MetricsEnum.Failed.ToString(), new string[] { string.Format("Client={0}", MetricsTagEnum.V1.ToString()) });
#endif
                    m_localLog.Error(ex);
                    string content = string.Format("批量插入数据异常,原因:{0},IsHandle:{1}", ex.ToString(), isHandle);
                    RecordLogCenterState("分布式日志1.0", content, isHandle, false);
                }
            }
            int insertResult = LogMessageDAL.GetInstance().Insert(buffer.GetEnumerator(), isHandle);
#if THRIFT
            if (insertResult > 0)
            {
                AppMetricsKeys.LogCenterClient.MeterMark(MetricsEnum.Success.ToString(), new string[] { string.Format("Client={0}", MetricsTagEnum.Local.ToString()) });
            }
            else
            {
                AppMetricsKeys.LogCenterClient.MeterMark(MetricsEnum.Failed.ToString(), new string[] { string.Format("Client={0}", MetricsTagEnum.Local.ToString()) });
            }
#endif
            RecordLogCenterState("本地批量保存日志", string.Format("本地批量插入{0}条数据, IsHandler: {1}", logMessageList.Count, isHandle), isHandle, false);
        }
Esempio n. 6
0
 //直接插入日志表
 /// <summary>
 /// 直接插入日志表
 /// </summary>
 /// <param name="logMessage"></param>
 /// <param name="isHandle"></param>
 private static void InsertLog(LogMessage logMessage, bool isHandle)
 {
     LogMessageDAL.GetInstance().Insert(new List <LogMessage> {
         logMessage
     }.GetEnumerator(), isHandle);
 }