示例#1
0
        private void AppendToCsv(string filename, Arguments args)
        {
            var csv = new CsvFormatter();

            using (var writter = new StreamWriter($"{args.csv}/log.csv", true))
            {
                using (var reader = File.OpenText(filename))
                {
                    var line = reader.ReadLine();
                    while (line != null)
                    {
                        if (CheckvalidLine(line))
                        {
                            var formatdata = csv.ParseLine(line);
                            if (args.loglevel.Contains(formatdata.GetString().Split(',')[0]))
                            {
                                count++;
                                writter.WriteLine($"{count},{formatdata.GetString()}");
                            }
                        }
                        line = reader.ReadLine();
                    }
                }
            }
        }
示例#2
0
        private void AppendToCsv(string filename, Arguments args)
        {
            var csv = new CsvFormatter();

            // GS - FYI - Using can be used in a new way with C#8
            // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-8.0/using#detailed-design
            // It makes your statements like this:-

            /*------
             *  using var writer = new StreamWriter($"{args.csv}/log.csv", true);
             *  using var reader = File.OpenText(filename);
             *  var line = reader.ReadLine();
             *  while (line != null)
             *  {
             *      ....
             *      ....
             *      ...
             *  }
             * -----*/
            using (var writter = new StreamWriter($"{args.csv}/log.csv", true))
            {
                using (var reader = File.OpenText(filename))
                {
                    var line = reader.ReadLine();
                    while (line != null)
                    {
                        if (CheckvalidLine(line))
                        {
                            var formatdata = csv.ParseLine(line);
                            if (args.loglevel.Contains(formatdata.GetString().Split(',')[0]))
                            {
                                count++;
                                writter.WriteLine($"{count},{formatdata.GetString()}");
                            }
                        }
                        line = reader.ReadLine();
                    }
                }
            }
        }