Handling System.IO.File methods in C#

  • Thread starter Thread starter hagaihe
  • Start date Start date
H

hagaihe

Hello,
My application is writing relevent events to log file on local machine.
Due to amount of transactions i need to open new log everyday and to
save the last one according to the next flow:

If the log file exists , check what is the log file creation date ,
compare it to the running logical day [ DateTime.Now.Day ] and if they
are not the same open new log file and add to the log file name the
creation date [ logfilename_dd_mm_yyyy.log ] and copy all the data from
current existing log to the new one.

So far so good ...

After doing that i delete the existing one [
System.IO.File.Delete(logfile name) ] and starts to write new events in
new log which has the same name by using : System.IO.File.AppendAllText
method. this methood checks if the logfile name which was givven as a
parameter exists and if not first create it.

The problem is when this methood creates the file again after it had
been deleted , the creation date is still of the last day and not of
the currnet logical one.

Does anyone have a solution??

10x.
 
Hello, (e-mail address removed)!

[skipped]

h> The problem is when this methood creates the file again after it had
h> been deleted , the creation date is still of the last day and not of
h> the currnet logical one.

h> Does anyone have a solution??

Take a look at File.SetCreationTime(...) static method.

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top