Home > DeveloperSection > Forums > Creating a new log file each day
Ashish Pandey

Total Post:128

Points:898
Posted on    November-13-2013 7:23 AM

 C# C# 
Ratings:


 1 Reply(s)
 646  View(s)
Rate this:

I need to create a log file daily in my working business hours.

Basically I need two things:-

1.       How can I create a new log file each day? The log file will be have the name in a format like MMDDYYYY.txt

2.       How can I create it just after midnight in case it is running into all hours of the night?



ezra heywood
ezra heywood

Total Post:145

Points:1019
Posted on    November-13-2013 7:47 AM

Hi Ashish,

I willrecommend something like this:

    string logFile = DateTime.Now.ToString("yyyyMMdd") + ".txt";

    if (!System.IO.File.Exists(logFile))

    {

         System.IO.File.Create(logFile);

    }

else

{

//append to logFile here...

}


Don't want to miss updates? Please click the below button!

Follow MindStick