Log Data to a File

You can easily write a collection of data to a log file by using System.IO.File.WriteAllLines method.System.IO.File.WriteAllLines The File.WriteAllLines method take two parameters, the output file and a collection of string entries. The method writes each entry on a new line.

using System; 
using System.Collections.Generic;
using System.Linq; using System.Text; 
using System.IO; 
namespace Cupofdev 
{
     class Cupofdev
      { 
          static void Main(string[] args) 
          { 
              // Create a list and populate it. 
              List<string> lstEntry = new List<string>();
              lstEntry.Add("Application Startup");
              lstEntry.Add("Executing Job 123"); 
              lstEntry.Add("Thank you for visiting www.cupofdev.com");
              // Write all of the entries to a file. 
              File.WriteAllLines("mylogfile.log", lstEntry); 
          } 
      } 
  } 
Built with Hugo
Theme Stack designed by Jimmy