CREATING A NEW LOG FILE EACH DAY

Ashish Pandey

Total Post:128

Points:898
Posted by  Ashish Pandey
C# 
C#
 933  View(s)
Ratings:
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?

  1. ezra heywood

    Post:145

    Points:1019
    Re: Creating a new log file each day

    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...

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!