---
title: "Creating a new log file each day"  
description: "Creating a new log file each day"  
author: "Anonymous User"  
published: 2013-11-13  
updated: 2013-11-13  
canonical: https://www.mindstick.com/forum/1717/creating-a-new-log-file-each-day  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Creating a new log file each day

I need to create a [log file](https://www.mindstick.com/articles/327201/create-log-file-in-c-sharp) daily in my working [business](https://www.mindstick.com/articles/12213/how-to-start-a-jewellery-making-business-online-business-ideas) [hours](https://answers.mindstick.com/qa/101444/who-s-the-youngest-winner-of-the-le-mans-24-hours-race).

Basically I need two things:-

1. How can I create a new log file each day? The log file will be have the [name](https://yourviews.mindstick.com/view/87450/how-to-generate-a-brand-name-using-linkedin-comprehensive-guide) in a [format](https://www.mindstick.com/forum/162083/how-to-convert-ost-files-into-pst-format) like MMDDYYYY.txt

2. How can I create it just after midnight in case it is running into all hours of the night?

## Replies

### Reply by Anonymous User

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...}
```


---

Original Source: https://www.mindstick.com/forum/1717/creating-a-new-log-file-each-day

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
