Beispiel #1
0
        /// <summary>
        /// 填充记录  要找到-----------------然后停止
        /// </summary>
        /// <param name="operation"></param>
        private void GetBody(Operation operation)
        {
            if (operation == null)
            {
                return;
            }
            //不用扫描寻找关键字
            string content = string.Empty;

            if (operation.logEntrys == null)
            {
                operation.logEntrys = new List <LogEntry>();
            }

            while (!Reader.EndOfStream)
            {
                try
                {
                    content = Reader.ReadLine().Replace("100%", "").Replace("0%", "").Trim();;
                    if (string.IsNullOrWhiteSpace(content))
                    {
                        continue;
                    }
                    if (IsEndLine(content))
                    {
                        break;
                    }

                    //判断是否出错
                    if (content.Contains(KeyUtil.ErrorKey))
                    {
                        #region 解析错误记录
                        LogEntry le = new LogEntry()
                        {
                            LType = LogType.ERROR
                        };
                        //出错信息解析
                        le.Time = content.Substring(0, content.IndexOf(KeyUtil.ErrorKey)).Trim();
                        #region 获取path
                        int index = content.IndexOf('\\');

                        if (content[index - 1] == ':')
                        {
                            le.Path = content.Substring(index - 2).Trim();
                        }
                        else
                        {
                            le.Path = content.Substring(index - 1).Trim();
                        }

                        #endregion
                        le.Cause = Reader.ReadLine().Trim();

                        operation.logEntrys.Add(le);
                        continue;
                        #endregion
                    }
                    else if (content.Contains(KeyUtil.RetryErrorKey))
                    {
                        continue;
                    }
                    else
                    {
                        #region 解析正常记录
                        if (content[0] != '*')
                        {
                            string[] paras = content.Split(new char[] { '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            LogEntry le    = new LogEntry()
                            {
                                LType = CultureManager.GetLogType(paras[0]),
                                Size  = paras[1],
                                Path  = paras[2]
                            };
                            operation.logEntrys.Add(le);
                        }
                        else
                        {
                            LogEntry le = new LogEntry();
                            le.LType = CultureManager.GetLogType(content.Substring(0, 11));
                            string[] paras = content.Substring(11).Split(new char[] { '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            le.Size = paras[0];
                            le.Path = paras[1];

                            operation.logEntrys.Add(le);
                        }
                        #endregion
                    }
                }
                catch (System.Exception ex)
                {
                    logger.Error(ex.Message);
                }
            }
        }