Esempio n. 1
0
        /// <summary>
        /// 写入日志
        /// </summary>
        /// <param name="strFilePath">日志路径</param>
        /// <param name="s1">内容1:
        /// EnumLogType.ErrorLog;(错误代码)
        /// EnumLogType.OperateLog;(操作员)
        /// EnumLogType.SuggestionLog;(建议人)
        /// EnumLogType.SystemLog;(系统名)
        /// EnumLogType.UpdateLog;(更新版本)
        /// </param>
        /// 
        /// <param name="s2">内容2
        /// EnumLogType.ErrorLog;(错误内容)
        /// EnumLogType.OperateLog;(操作内容)
        /// EnumLogType.SuggestionLog;(建议内容)
        /// EnumLogType.SystemLog;(系统操作内容)
        /// EnumLogType.UpdateLog;(更新内容)
        /// </param>
        /// <param name="enumLogType">日志类型</param>
        /// <returns>是否保存成功</returns>
        public static bool Write(EnumLogType enumLogType, string strFilePath, string s1, string s2)
        {
            Log log = null;

            switch (enumLogType)
            {
                case EnumLogType.ErrorLog:
                    log = new ErrorLog();
                    ((ErrorLog)log).ErrorCode = s1;
                    ((ErrorLog)log).ErrorValue = s2;
                    break;

                case EnumLogType.OperateLog:
                    log = new OperateLog();
                    ((OperateLog)log).Operater = s1;
                    ((OperateLog)log).OperateValue = s2;
                    break;

                case EnumLogType.SuggestionLog:
                    log = new SuggestionLog();
                    ((SuggestionLog)log).Sender = s1;
                    ((SuggestionLog)log).SuggestionValue = s2;
                    break;

                case EnumLogType.SystemLog:
                    log = new SystemLog();
                    ((SystemLog)log).SystemName = s1;
                    ((SystemLog)log).Operate = s2;
                    break;

                case EnumLogType.UpdateLog:
                    log = new UpdateLog();
                    ((UpdateLog)log).UpdateVerson = s1;
                    ((UpdateLog)log).UpdateValue = s2;
                    break;

                default:
                    break;
            }

            //return SaveLogData(log, strFilePath);
            return log.SaveLogData(strFilePath);
        }
Esempio n. 2
0
        /// <summary>
        /// 查询日志
        /// </summary>
        /// <param name="path">日志路径</param>
        /// <param name=param name="enumLogType">日志类型</param>
        /// <returns>日志DataTable</returns>
        public static DataTable GetLogs(string path, EnumLogType enumLogType)
        {
            try
            {
                Log log = null;

                switch (enumLogType)
                {
                    case EnumLogType.ErrorLog:
                        log = new ErrorLog();

                        break;

                    case EnumLogType.OperateLog:
                        log = new OperateLog();

                        break;

                    case EnumLogType.SuggestionLog:
                        log = new SuggestionLog();

                        break;

                    case EnumLogType.SystemLog:
                        log = new SystemLog();

                        break;

                    case EnumLogType.UpdateLog:
                        log = new UpdateLog();

                        break;

                    default:
                        break;
                }

                DataTable dt = new DataTable();

                PropertyInfo[] pinfo = log.GetType().GetProperties();

                for (int i = 0; i < pinfo.Length; i++)
                {
                    DataColumn dc = new DataColumn(pinfo[i].Name);
                    dt.Columns.Add(dc);
                }


                XmlDocument doc = XMLHelper.EntityToXmlByObject(path, log);
                
                XmlNode node = doc.SelectSingleNode(log.GetType().Name);

                if (node != null)
                {
                    foreach (XmlNode lognode in node.ChildNodes)
                    {
                        DataRow dr = dt.NewRow();
                        foreach (XmlNode cnode in lognode.ChildNodes)
                        {
                            dr[cnode.Name] = cnode.InnerText;
                        }
                        dt.Rows.Add(dr);
                    }
                }

                return dt;
            }
            catch
            {
                return null;
            }
        }