static void Main(string[] args) { String localdepart = ""; Console.WriteLine("Do You Want to Add Employees"); string choice = Console.ReadLine(); while (choice != "Exit") { EmployeeDetails emp = new EmployeeDetails(); Console.WriteLine("Employee Name:"); emp.EName = Console.ReadLine(); Console.WriteLine("Employee Id:"); emp.EmpId = Console.ReadLine(); Console.WriteLine("Employee Age:"); emp.EmpAge = Console.ReadLine(); Console.WriteLine("Employee Contact Number:"); emp.Number = Console.ReadLine(); try { Console.WriteLine("Employee Qualification:"); emp.EmpQual = Console.ReadLine(); validateQualification(emp.EmpQual); if (emp.EmpQual.Equals("BE") || emp.EmpQual.Equals("B.SC") || emp.EmpQual.Equals("BCA")) { localdepart = "IT"; } else if (emp.EmpQual.Equals("B.COM") || emp.EmpQual.Equals("M.COM") || emp.EmpQual.Equals("CA")) { localdepart = "Accounts"; } emp.Depart = localdepart; Disp msg = new Disp(Display); msg(emp.EName, emp.Depart); list.Add(emp); } catch (QualificationRequiredException ex) { StreamWriter str = null; Console.WriteLine(ex.Message); using (FileStream file = new FileStream("C:\\Users\\raaja\\source\\repos\\Employee\\Employee\\log_test.txt", FileMode.Append)) { using (str = new StreamWriter(file)) str.WriteLine(ex.Message + " " + DateTime.Today.ToString("yyyyMMdd")); } // if (str != null) // str.Close();//streamwriter is closed manually } finally { Console.WriteLine("Do You Want to Add Employees or type exit"); choice = Console.ReadLine(); } } foreach (EmployeeDetails em in list) { Console.WriteLine(em.EName + " " + em.EmpId + " " + em.EmpAge + " " + em.Depart); } }