Пример #1
0
        /// <summary>
        /// 添加系统日志
        /// </summary>
        /// <returns></returns>
        protected void AddSysLog(string optType, string optContent, string system, string module, string otherMsg = "")
        {
            Type             t       = this.GetType();
            FuncMsgAttribute funcMsg = (FuncMsgAttribute)Attribute.GetCustomAttribute(t, typeof(FuncMsgAttribute));

            BaseSysLogModel sysLogModel = new BaseSysLogModel();

            sysLogModel.F_OptType    = optType;
            sysLogModel.F_OptContent = optContent;
            sysLogModel.F_OtherMsg   = otherMsg;

            try
            {
                sysLogModel.F_System = string.IsNullOrEmpty(system) ? Configs.GetSetting("systemFlag") : system;
                if (string.IsNullOrEmpty(module) && funcMsg != null)
                {
                    sysLogModel.F_Module = funcMsg.GetModuleFuncStr();
                }
                else
                {
                    sysLogModel.F_Module = module;
                }

                SysLogProvider.GetInstance().WirteSysLog(sysLogModel);
            }
            catch (Exception e)
            {
                MyLog.Error("批量写入日志出现错误", e);
            }
        }
Пример #2
0
        /// <summary>
        /// 添加系统日志
        /// </summary>
        /// <returns></returns>
        protected void AddSysLog(string optType, string optContent, string otherMsg = "")
        {
            Type             t       = this.GetType();
            FuncMsgAttribute funcMsg = (FuncMsgAttribute)Attribute.GetCustomAttribute(t, typeof(FuncMsgAttribute));

            BaseSysLogModel sysLogModel = new BaseSysLogModel();

            sysLogModel.F_OptType    = optType;
            sysLogModel.F_OptContent = optContent;
            sysLogModel.F_OtherMsg   = otherMsg;

            try
            {
                sysLogModel.F_System = Configs.GetSetting("systemFlag");
                if (funcMsg == null)
                {
                    sysLogModel.F_Module = "";
                    MyLog.Error("未配置该方法的FuncMsg信息:" + t.FullName);
                }
                else
                {
                    sysLogModel.F_Module = funcMsg.GetModuleFuncStr();
                }

                SysLogProvider.GetInstance().WirteSysLog(sysLogModel);
            }
            catch (Exception e)
            {
                MyLog.Error("写入日志出现错误", e);
            }
        }
Пример #3
0
        /// <summary>
        /// 日志输出的方法
        /// </summary>
        /// <returns></returns>
        public void WirteSysLog(BaseSysLogModel sysLogModel)
        {
            //1、完善日志要输出的实例,主要是id,用户,时间信息,只有当前系统的日志才会进行处理。
            if (sysLogModel.F_System.Equals(Configs.GetSetting("systemFlag")))
            {
                sysLogModel.Create();
            }

            //2、获取配置的输出方式
            string logTypeConfig = Configs.GetSetting("logSaveType");

            string[] logTypeArray = logTypeConfig.Split(',');

            //3、根据不同类型进行输出操作
            string logOutputMsg = "";

            foreach (string logTypeStr in logTypeArray)
            {
                lock (allSysLog)
                {
                    if (allSysLog.ContainsKey(logTypeStr))
                    {
                        List <ISysLog> sysLogList = allSysLog[logTypeStr];
                        foreach (ISysLog sysLog in sysLogList)
                        {
                            if (!sysLog.AddSysLog(sysLogModel))
                            {
                                //如果输出失败了,则记录输出错误的类,然后最终输出到错误日志。
                                logOutputMsg += sysLog.GetType().FullName + ",";
                            }
                        }
                    }
                }
            }

            //4、记录输出错误的日志
            if (!string.IsNullOrEmpty(logOutputMsg))
            {
                MyLog.Error("日志输出出现错误,方法为:" + logOutputMsg + ";日志内容为:" + sysLogModel.ToString());
            }
        }