public void AddDataToTheFile(int no, DateTime date, string level, string text, string filepath) { try { using (System.IO.StreamWriter file = new System.IO.StreamWriter(filepath, true)) { _csvfile.SetNo(++no); if (new FileInfo(filepath).Length == 0) { string header = "No| Date | Time |Level | Text |\n"; file.WriteLine(header); } file.WriteLine(no + "|" + date + "|" + level + "|" + text); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }