Example #1
0
        public InputParameters GetInputParameters(string[] args)
        {
            bool isLogDir = false;
            bool isCsvDir = false;

            const string logFile  = InputParameters.inputDir;
            const string csvFile  = InputParameters.ouputDir;
            const string loglevel = InputParameters.LogLevel;

            InputParameters inputParameters = new InputParameters();
            Validations     validations     = new Validations();

            for (int index = 0; index < args.Length; index++)
            {
                switch (args[index])
                {
                case logFile:
                    if (!isLogDir)
                    {
                        inputParameters.logFilePath = args[++index];
                        isLogDir = true;
                    }
                    break;

                case csvFile:
                    if (!isCsvDir)
                    {
                        inputParameters.csvFilePath = args[++index];
                        isCsvDir = true;
                    }
                    break;

                case loglevel:
                    inputParameters.loglevel.Add(args[++index]);
                    break;

                case "--help":
                case "-h":
                    validations.ShowAppropriateUsage();
                    throw new Exception();

                default:
                    Console.WriteLine("Invalid input Paramters Passed");
                    break;
                }
            }

            return(inputParameters);
        }
        public List <string> ReadLogFiles(InputParameters inputParameters)
        {
            string logFileDir = inputParameters.logFilePath;

            string[] files = GetLogFiles(logFileDir);

            List <string> logs = new List <string>();
            string        line;

            Console.WriteLine("***LogParser: Log files converting to Csv***");
            Console.WriteLine("Log files converted to Csv is/are:");

            foreach (var file in files)
            {
                try
                {
                    using (StreamReader sr = new StreamReader(file))
                    {
                        while ((line = sr.ReadLine()) != null)
                        {
                            if (line.Length > 10)
                            {
                                logs.Add(line);
                            }
                        }
                    }
                }
                catch (IOException e)
                {
                    Console.WriteLine("Could not read file/files from --log-dir", logFileDir);
                    Console.WriteLine(e.Message);
                }

                Console.WriteLine(file);
            }

            List <string> activeLogs = GetRequiredLogs(logs, inputParameters.loglevel);

            return(activeLogs);
        }
Example #3
0
        public static void Main(string[] args)
        {
            InputParameters        inputParameters        = new InputParameters();
            LogParserUtil          logParserUtil          = new LogParserUtil();
            ProcessLogParameters   processLogParameters   = new ProcessLogParameters();
            GenerateCsv            generateCsv            = new GenerateCsv();
            ProcessInputParameters processInputParameters = new ProcessInputParameters();
            Validations            validations            = new Validations();



            validations.ValidateInputArguments(args);

            inputParameters = processInputParameters.GetInputParameters(args);

            validations.ValidateLogLevels(inputParameters.loglevel);

            List <string> activeLogs = logParserUtil.ReadLogFiles(inputParameters);

            var logParameters = processLogParameters.GenerateLogParamters(activeLogs);

            generateCsv.CreateCsvFile(logParameters, inputParameters.csvFilePath);
        }