Пример #1
0
 /// <summary>
 /// Function to parse dabase log table
 /// </summary>
 /// <param name="config"></param>
 /// <returns></returns>
 public override List<LogMessage> Parse(Log2Console.Configuration.Configuration config)
 {
     try
     {
         ConfigurationSettings setting = config.Configurations;
         List<LogMessage> logMsgs = GetLoggerItems(setting.FieldList, setting.ConnectionString, setting.LogTableName, setting.RowsCount);
         return logMsgs;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #2
0
        /// <summary>
        /// Function to parse flat log file
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public override List<LogMessage> Parse(Log2Console.Configuration.Configuration config)
        {
            ConfigurationSettings setting = config.Configurations;//Get parameters which has been passed from Receiver.
            string line;
            var sb = new StringBuilder();
            List<LogMessage> logMsgs = new List<LogMessage>();

            /////////////////////////////////////////////////////////////
            //To get conversion pattern string arrayk
            LoggerFormatParser formatparser = new LoggerFormatParser();
            formatparser.ParseLog4J4NetFormatString(setting.ConversionPattern);
            ////////////////////////////////////////////////////////////

            while ((line = setting.FileReader.ReadLine()) != null)
            {
                if (!string.IsNullOrEmpty(line))
                {
                    int errorCount = 0;
                    LogMessage logMsg = new LogMessage();
                    try
                    {
                        //////////////////////////////////////////////////////
                        foreach (var item in formatparser.ColInfoList)
                        {
                            string[] stringSeparators = new string[] { item.TrailingSeparator };
                            string separator = stringSeparators[0].ToString();
                            string[] strResult = new string[0];
                            string dataValue;

                            strResult = line.Split(stringSeparators, StringSplitOptions.None);
                            if (!string.IsNullOrEmpty(item.FormatString))//for datetime string cut value exactly same as formatstring instead separator
                            {
                                if (strResult[0].Length <= 10)
                                    dataValue = strResult[0] + separator + strResult[1];
                                else
                                    dataValue = strResult[0];
                            }
                            else
                            {

                                dataValue = strResult[0];
                            }


                            errorCount = LoggerFormatParser.SetLogMsgObj(dataValue, item.Header.ToLower(), logMsg, item.FormatString);//Get logMsg object filled.
                            if (errorCount > 0)//Case of stack trace where next complete line is the part of previous message.
                                break;

                            int count = 0;

                            if (!string.IsNullOrEmpty(line))
                            {
                                if (!string.IsNullOrEmpty(item.FormatString))//for datetime string cut exactly same as formatstring
                                {
                                    count = (item.FormatString + separator).Length;
                                    line = line.Remove(0, count);
                                }
                                else if (item.MinLength > 0)//case %-5level, where length is defined for level column value is 5
                                {
                                    count = item.MinLength + separator.Length;
                                    line = line.Remove(0, count);
                                }
                                else
                                    line = line.Replace(strResult[0] + separator, "");//Simple case where we need to cut already processed area from text line
                            }
                        }
                        //////////////////////////////////////////////////////
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }

                    if (errorCount > 0)//Case of stack trace where next complete line is the part of previous message.
                        logMsgs[logMsgs.Count - 1].Message += Environment.NewLine + line;//Append this line into previous message.
                    else
                        logMsgs.Add(logMsg);
                }
            }

            return logMsgs;
        }
Пример #3
0
 /// <summary>
 /// Function to parse log object to get all logs
 /// </summary>
 /// <param name="config"></param>
 /// <returns></returns>
 public virtual List<LogMessage> Parse(Log2Console.Configuration.Configuration config)
 {
     List<LogMessage> lst = new List<LogMessage>();
     return lst;
 }