示例#1
0
 public Tuple <bool, string> DeleteImportBankMRActivityByBatchCode(string batchCode, string operateUser)
 {
     try
     {
         var result = TuhuGrouponDbScopeManager.Execute(conn => BankMRActivityDal.DeleteImportBankMRActivityByBatchCode(conn, batchCode));
         if (result)
         {
             var log = new BeautyOprLog
             {
                 LogType     = "DeleteImportBankMRActivityUsers",
                 IdentityID  = $"{batchCode}",
                 OldValue    = null,
                 NewValue    = null,
                 Remarks     = $"活动场次删除用户规则,batchCode:{batchCode},",
                 OperateUser = operateUser,
             };
             LoggerManager.InsertLog("BeautyOprLog", log);
         }
         return(Tuple.Create(result, ""));
     }
     catch (Exception ex)
     {
         Logger.Warn(ex.Message, ex);
         return(Tuple.Create(false, ex.Message));
     }
 }
示例#2
0
        public void Log <TState>(ML.LogLevel logLevel, ML.EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            var msg = formatter(state, exception);

            switch (logLevel)
            {
            case ML.LogLevel.Critical:
                logger.Fatal(msg);
                return;

            case ML.LogLevel.Debug:
                logger.Debug(msg);
                return;

            case ML.LogLevel.Error:
                logger.Error(msg);
                return;

            case ML.LogLevel.Information:
                logger.Info(msg);
                return;

            case ML.LogLevel.Trace:
                logger.Trace(msg);
                return;

            case ML.LogLevel.Warning:
                logger.Warn(msg);
                return;
            }
        }
        /// <summary>
        /// 清除缓存
        /// </summary>
        /// <param name="pids"></param>
        /// <returns></returns>
        public async Task <bool> RemoveCache(List <string> pids)
        {
            var result = false;

            try
            {
                using (var client = new Service.BaoYang.CacheClient())
                {
                    var batchSize = 200;
                    for (var i = 0; i < Math.Ceiling(pids.Count * 1.0 / batchSize); i++) //分批清除缓存 每批次200个
                    {
                        var clientResult = await client.RemoveByTypeAsync
                                               ("BatteryCouponPriceDisplay", pids.Skip(i *batchSize).Take(batchSize).ToList());

                        result = clientResult.Success;
                        if (!result && clientResult.Exception != null)
                        {
                            Logger.Warn("调用BaoYang服务RemoveByTypeAsync失败", clientResult.Exception);
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("RemoveCache", ex);
            }
            return(result);
        }
示例#4
0
 private static void LogPrint(LoggingCommon.ILog log)
 {
     log.Info("info message");
     log.Error(new InvalidDataException("just testing"));
     log.Debug("debug message");
     log.Warn("warn message");
     log.Error("error message");
     log.Fatal("fatal message");
 }
示例#5
0
        /// <summary>
        /// 消息輸出
        /// </summary>
        /// <param name="message">消息</param>
        /// <param name="level">級別</param>
        /// <param name="exception">異常對象</param>
        public void Output(string message, MessageLevel level, Exception exception)
        {
            Common.Logging.ILog logger = LogManager.GetLogger(GetType());
            switch (level)
            {
            case MessageLevel.Trace:
                if (logger.IsTraceEnabled)
                {
                    logger.Trace(message, exception);
                }
                break;

            case MessageLevel.Debug:
                if (logger.IsDebugEnabled)
                {
                    logger.Debug(message, exception);
                }
                break;

            case MessageLevel.Info:
                if (logger.IsInfoEnabled)
                {
                    logger.Info(message, exception);
                }
                break;

            case MessageLevel.Warn:
                if (logger.IsWarnEnabled)
                {
                    logger.Warn(message, exception);
                }
                break;

            case MessageLevel.Error:
                if (logger.IsErrorEnabled)
                {
                    logger.Error(message, exception);
                }
                break;

            case MessageLevel.Fatal:
                if (logger.IsFatalEnabled)
                {
                    logger.Fatal(message, exception);
                }
                break;
            }
        }
        public static void LogEx(this Common.Logging.ILog log, Common.Logging.LogLevel level, Action <TraceRecord> traceAction, [CallerMemberName] string member = "", [CallerLineNumber] int line = 0)
        {
            // Check if this log level is enabled
            if (level == LogLevel.Trace && log.IsTraceEnabled == false ||
                level == LogLevel.Debug && log.IsDebugEnabled == false ||
                level == LogLevel.Info && (log.IsInfoEnabled == false) ||
                level == LogLevel.Warn && (log.IsWarnEnabled == false) ||
                level == LogLevel.Error && (log.IsErrorEnabled == false) ||
                level == LogLevel.Fatal && (log.IsFatalEnabled == false))
            {
                return;
            }

            TraceRecord tr = new TraceRecord()
            {
                Level = level
            };

            traceAction(tr);
            string message = String.Format("{0}() line {1}: {2}.{3}", member, line, tr.Message, (tr.Data != null) ? Newtonsoft.Json.JsonConvert.SerializeObject(tr.Data) : "");

            switch (level)
            {
            case LogLevel.Trace: log.Trace(message, tr.Exception); break;

            case LogLevel.Debug: log.Debug(message, tr.Exception); break;

            case LogLevel.Error: log.Error(message, tr.Exception); break;

            case LogLevel.Fatal: log.Fatal(message, tr.Exception); break;

            case LogLevel.Info: log.Info(message, tr.Exception); break;

            case LogLevel.Warn: log.Warn(message, tr.Exception); break;
            }
        }
示例#7
0
 public void Warn(object obj)
 {
     _log.Warn(obj);
 }
        public void Execute(IJobExecutionContext context)
        {
            try
            {
                const int pageSize  = 800;
                decimal   num       = ProductCacheDal.SelectSkuProductCount();
                var       pageNum   = Convert.ToInt32(Math.Ceiling(num / pageSize));
                bool      issuccess = true;
                string    key       = "";
                Logger.Info($"{JobBatch}=>刷新缓存服务开始.一共{num}个产品.一共{pageNum}批次.");
                Stopwatch watch = new Stopwatch();
                watch.Start();

                if (DateTime.Now.Hour >= 2 && DateTime.Now.Hour <= 4)
                {
                    using (var cacheclient = new CacheClient())
                    {
                        var keyresult = cacheclient.GenerateProdutCacheKeyPrefix();
                        keyresult.ThrowIfException(true);
                        key = keyresult.Result;
                    }
                }

                var client = new CacheClient();
                for (var i = 1; i <= pageNum + 1; i++)
                {
                    Thread.Sleep(5);
                    var result = client.RefreshProductCacheByPageNumAndKeyPrefix(i, pageSize, JobBatch, key);
                    Logger.Info($"{JobBatch}=>{i}批次刷新{(result.Result ? "成功" : "失败")}.用时{result.ElapsedMilliseconds}");

                    if (!result.Success || !result.Result) //失败重新创建client
                    {
                        Thread.Sleep(1000);
                        client = new CacheClient();
                        var result2 = client.RefreshProductCacheByPageNumAndKeyPrefix(i, pageSize, JobBatch, key);
                        Logger.Info($"{JobBatch}=>{i}批次重试刷新{(result2.Result ? "成功" : "失败")}.用时{result2.ElapsedMilliseconds}");

                        if (!result2.Success) //失败重新创建client
                        {
                            client = new CacheClient();
                        }
                    }
                    issuccess = issuccess && result.Result;
                }

                using (var cacheclient = new CacheClient())
                {
                    var setresult = cacheclient.SetProdutCacheKeyPrefix(key);
                    if (!setresult.Success && setresult.ErrorCode != "keyPrefix")
                    {
                        Logger.Warn($"刷新产品缓存,换key失败。{setresult.ErrorMessage}", setresult.Exception);
                    }
                    Logger.Info($"{JobBatch}=>刷新产品缓存.换key.{setresult.Result};key=>{key}");
                }

                watch.Stop();
                if (issuccess)
                {
                    Logger.Info($"{JobBatch}=>刷新成功用时{watch.ElapsedMilliseconds}");
                }
                else
                {
                    Logger.Error($"{JobBatch}=>刷新失败用时{watch.ElapsedMilliseconds}");
                }
            }
            catch (Exception e)
            {
                Logger.Error($"{JobBatch}=>刷新产品缓存异常", e);
            }
            JobBatch++;
        }
示例#9
0
 /// <summary>
 /// Log a message string with the Warn level.
 /// </summary>
 /// <param name="message">The message.</param>
 public void Warn(string message)
 {
     _logger.Warn(message);
 }
示例#10
0
        private void Write(LogEntity log)
        {
            var workType = LogManager.MatchLogWorkType(log.AppName, log.ModelName, log.BusinessName, log.Lable, log.ServerName);

            if (workType == LogWorkType.Local || workType == LogWorkType.LocalAndBuffer)
            {
                switch (log.Level)
                {
                case LogLevel.DEBUG:
                    if (LogManager.MatchLogLevel(log.Level, log.AppName, log.ModelName, log.BusinessName, log.Lable, log.ServerName))
                    {
                        loggerForDebug.Debug(log.ToString());
                    }
                    break;

                case LogLevel.ERROR:
                    if (LogManager.MatchLogLevel(log.Level, log.AppName, log.ModelName, log.BusinessName, log.Lable, log.ServerName))
                    {
                        loggerForError.Error(log.ToString());
                    }
                    break;

                case LogLevel.WARN:
                    if (LogManager.MatchLogLevel(log.Level, log.AppName, log.ModelName, log.BusinessName, log.Lable, log.ServerName))
                    {
                        loggerForWarn.Warn(log.ToString());
                    }
                    break;

                case LogLevel.INFO:
                    if (LogManager.MatchLogLevel(log.Level, log.AppName, log.ModelName, log.BusinessName, log.Lable, log.ServerName))
                    {
                        loggerForInfo.Info(log.ToString());
                    }
                    break;
                }
            }

            if (workType == LogWorkType.Buffer || workType == LogWorkType.LocalAndBuffer)
            {
                if (BufferServiceManager.HasInited && BufferServiceManager.DispatcherService.IsRunning)
                {
                    switch (log.Level)
                    {
                    case LogLevel.DEBUG:
                        if (LogManager.MatchLogLevel(log.Level, log.AppName, log.ModelName, log.BusinessName, log.Lable, log.ServerName))
                        {
                            BufferServiceManager.TransportService.Transport(log);
                        }
                        break;

                    case LogLevel.ERROR:
                        if (LogManager.MatchLogLevel(log.Level, log.AppName, log.ModelName, log.BusinessName, log.Lable, log.ServerName))
                        {
                            BufferServiceManager.TransportService.Transport(log);
                        }
                        break;

                    case LogLevel.WARN:
                        if (LogManager.MatchLogLevel(log.Level, log.AppName, log.ModelName, log.BusinessName, log.Lable, log.ServerName))
                        {
                            BufferServiceManager.TransportService.Transport(log);
                        }
                        break;

                    case LogLevel.INFO:
                        if (LogManager.MatchLogLevel(log.Level, log.AppName, log.ModelName, log.BusinessName, log.Lable, log.ServerName))
                        {
                            BufferServiceManager.TransportService.Transport(log);
                        }
                        break;
                    }
                }
            }
        }