コード例 #1
0
ファイル: LogReportIO.cs プロジェクト: macieja79/budget
        public LogReportPack CreateFromLines(string[] lines)
        {
            LogReportPack pack          = new LogReportPack();
            LogReport     parsedReport  = null;
            LogReport     currentReport = null;

            LogReportItem item = null;

            foreach (string line in lines)
            {
                if (LogReport.TryCreateFromHeader(line, out parsedReport))
                {
                    currentReport = parsedReport;
                    pack.Reports.Add(currentReport);
                    continue;
                }

                if (LogReportItem.TryCreateFromString(line, out item))
                {
                    if (null != currentReport)
                    {
                        currentReport.Items.Add(item);
                    }
                }
            }

            return(pack);
        }
コード例 #2
0
ファイル: LogReportItem.cs プロジェクト: macieja79/budget
        public static bool TryCreateFromString(string pattern, out LogReportItem item)
        {
            item = null;

            try
            {
                int headerLength = _headerPattern.Length;
                if (pattern.Length < headerLength + 2)
                {
                    return(false);
                }

                string header = pattern.Substring(0, headerLength);

                bool isPattern = pattern[0] == '[' && pattern[4] == '|' &&
                                 pattern[7] == '|' && pattern[16] == ']';

                if (!isPattern)
                {
                    return(false);
                }

                string type     = MtString.GetSubString(pattern, 0, 4, false);
                string strLevel = MtString.GetSubString(pattern, 4, 7, false);
                string date     = MtString.GetSubString(pattern, 7, 16, false);
                string tempMsg  = pattern.Substring(18);
                string msg      = tempMsg.Replace(ITEM_SEPARATOR, Environment.NewLine);


                LogReportItemType typeofReport = GetLogReportType(type);
                int      level = int.Parse(strLevel);
                DateTime dt    = DateTime.Parse(date);

                item = new LogReportItem
                {
                    TypeOfLogItem = typeofReport,
                    Level         = level,
                    Date          = dt,
                    Message       = msg
                };

                return(true);
            }
            catch (Exception exc)
            {
            }

            return(false);
        }
コード例 #3
0
        public void Log(string message, int level, LogReportItemType type)
        {
            LogReportItem item = new LogReportItem()
            {
                Date          = DateTime.Now,
                Level         = level,
                Message       = message,
                TypeOfLogItem = type
            };

            if (null != Current)
            {
                Current.Items.Add(item);
            }
        }