Пример #1
0
        /// <summary>
        /// Thrift实现方法
        /// </summary>
        /// <param name="logPackage"></param>
        public void Log(TLogPackage logPackage)
        {
            int over_count = queue.Enqueue(logPackage);



            //sizeof(logPackage)
            //logPackage.
            #region 溢出处理

            if (over_count > 0)
            {
                string msg           = "Logging_Server_Queue溢出数量:" + over_count + " 。 建议增加 BlockingQueueLength 配置值";
                var    over_log_tags = new List <string> {
                    "_title_=Logging_Server_Over"
                };

                LogEntity over_log = new LogEntity();
                over_log.IP      = ServerIPNum;
                over_log.Level   = LogLevel.Error;
                over_log.Message = msg;
                over_log.Tags    = over_log_tags;
                over_log.Title   = "Logging_Server_Over";
                over_log.Source  = "Logging.Server.LogReciver";
                over_log.Thread  = Thread.CurrentThread.ManagedThreadId;
                over_log.Time    = Utils.GetTimeStamp(DateTime.Now);
                over_log.AppId   = server_appId;

                List <LogEntity> over_logs = new List <LogEntity>();
                //over_logs.Add(over_log);
                //ProcessLog(over_logs);

                var processor = LogProcessorManager.GetLogProcessor();
                processor.Process(over_logs);
            }

            #endregion 溢出处理
        }
Пример #2
0
        private static void ProcessLog(TLogPackage logPackage)
        {
            if (logPackage.LogItems == null || logPackage.LogItems.Count == 0)
            {
                return;
            }

            List <TLogEntity> logEntities = logPackage.LogItems;
            var _logEntities = new List <LogEntity>();

            var log_on_off = LogOnOffManager.GetLogOnOff(logPackage.AppId);

            foreach (var item in logEntities)
            {
                if (item.Level == (int)LogLevel.Debug && log_on_off.Debug == 0)
                {
                    continue;
                }
                if (item.Level == (int)LogLevel.Info && log_on_off.Info == 0)
                {
                    continue;
                }
                if (item.Level == (int)LogLevel.Warm && log_on_off.Warm == 0)
                {
                    continue;
                }
                if (item.Level == (int)LogLevel.Error && log_on_off.Error == 0)
                {
                    continue;
                }

                List <string> tags = new List <string>();

                if (item.Tags != null && item.Tags.Count > 0)
                {
                    foreach (var tag in item.Tags)
                    {
                        tags.Add(tag.Key.Replace("=", string.Empty) + "=" + tag.Value);
                    }
                }

                LogEntity _log = new LogEntity();
                _log.IP      = logPackage.IP;
                _log.Level   = (LogLevel)item.Level;
                _log.Message = item.Message;
                _log.Tags    = tags;
                _log.Title   = item.Title;
                _log.Source  = item.Source;
                _log.Thread  = item.Thread;
                _log.Time    = item.Time;
                _log.AppId   = logPackage.AppId;
                _logEntities.Add(_log);
            }

            if (_logEntities.Count == 0)
            {
                return;
            }

            var processor = LogProcessorManager.GetLogProcessor();

            processor.Process(_logEntities);
        }