示例#1
0
        /// <summary>
        /// Write all the logs consistently into the database table Logs
        /// </summary>
        /// <param name="proc"> The process to be executed </param>
        private void SaveLogs(Process proc)
        {
            proc.Start();
            while (!proc.StandardOutput.EndOfStream && !_token.IsCancellationRequested)
            {
                string line = proc.StandardOutput.ReadLine();
                if (!string.IsNullOrEmpty(line) && !line.StartsWith("---------"))
                {
                    line = _device.Serial + " " + _device.Name + " " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " " + line;

                    try
                    {
                        var grokResult = _grok.Parse(line);
                        _tableLogs.InsertValues(grokResult[0].Value.ToString(), grokResult[1].Value.ToString(),
                                                Convert.ToDateTime(grokResult[2].Value), Convert.ToDateTime(grokResult[3].Value),
                                                Convert.ToInt32(grokResult[4].Value), Convert.ToInt32(grokResult[5].Value),
                                                grokResult[6].Value.ToString(), grokResult[7].Value.ToString(), grokResult[8].Value.ToString());
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Error while logging ... continuing");
                    }
                }
            }
        }