web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :

Log Data to a File

Morne Wolfaardt Profile Picture Morne Wolfaardt

Log Data to a File

You can easily write a collection of data to a log file by using System.IO.File.WriteAllLines method.

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);
}
}
}

 

The post Log Data to a File appeared first on Cup of dev - A blog for developers by Morne Wolfaardt.


This was originally posted here.

Comments

*This post is locked for comments