Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6013633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:34:38+00:00 2026-05-23T02:34:38+00:00

I have a program that’s writing to a log file called appname_yyyyMMdd.log, where appname

  • 0

I have a program that’s writing to a log file called “appname_yyyyMMdd.log”, where appname is the name of my app, and yyyyMMdd is the current date; a sample log file name might be “loglistener_20110615.log” . Anyway, my app creates the log file fine, and it updates it as planned. However, once the date changes, the app doesn’t log anything, and it doesn’t create a new file. In other words, since today is 6/15, I need it to create a file called “loglistener_20110616.log” after midnight tonight, and I need it to continue logging to that new file.

Here are code excerpts:

public static void LogInfo(string format, params object[] args)
{
    lock (_logLock)
    {
        using (StreamWriter sw = File.AppendText(GetLogPath()))
        {
            sw.WriteLine(GetTimeStamp() + String.Format(format, args));
        }
    }
}

private static string GetLogPath()
{
    string appName = "loglistener";
    string today = DateTime.Today.ToString("yyyyMMdd");
    string fileName = appName + "_" + today + ".log";
    string fullLogPath = AppDomain.CurrentDomain.BaseDirectory + fileName;

    return fullLogPath;
}

I checked this similar question, but that question describes a different scenario (with a non-applicable fix).

UPDATE – Just in case googlers land on this page, I later discovered a different cause altogether w/ this. My log is logging info from an email-listening service. The service itself had a problem where it was timing out after a half-hour. So, my problem wasn’t w/ CreateText / AppendText… My problem was there was nothing to log. Very annoying, but I hope other people won’t be misled by this question/answer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:34:39+00:00Added an answer on May 23, 2026 at 2:34 am

    You should check to make sure that the file exists first.

    From the File.AppendText Documentation

    Type: System.IO.StreamWriter A
    StreamWriter that appends UTF-8
    encoded text to an existing file.

    public static void LogInfo(string format, params object[] args)
    {
        lock (_logLock)
        {
            using (StreamWriter sw = File.Exists(GetLogPath) ? File.AppendText(GetLogPath()) : File.CreateText(GetLogPath())
            {
                sw.WriteLine(GetTimeStamp() + String.Format(format, args));
            }
        }
    
    }
    

    Try that instead

    After looking at the comments and re-reading the documentation.

    File.AppendText
    

    Should always work, regardless of file existence.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that convert image file to binary and also it converts
I have a program that creates a html file as standard output. To view
I have a program that wants to be called from the command line many
I have a program that generates a static HTML file. I have a list
Have a program that's dynamically generating an Excel file and a csv. The excel
I have a program that reads in a file and does some parsing to
I have a program that wants to check if a file has been modified.
I have a program that read urls in a file and does a gethostbyname()
I have a program that I'm writing where I am using another company's library
I have a program that need to get multiple cstrings. I current get one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.