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 4067200
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:13:11+00:00 2026-05-20T16:13:11+00:00

I would like a new log file created everytime the application starts. If a

  • 0

I would like a new log file created everytime the application starts. If a log file already exists, I would like the existing one renamed. Is this possible? My current Listener entry looks like this

  <add name="QueueDiagListener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    fileName="C:\Logs\QueueDiag.log" footer="" formatter="MessageOnlyFormatter"
    header="" rollFileExistsBehavior="Increment" rollSizeKB="1024" />

What am i missing?

  • 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-20T16:13:12+00:00Added an answer on May 20, 2026 at 4:13 pm

    I’ve had the same issue numerous times. There doesn’t seem to be a way of solving this in a configurational manner. I always solve this issue in code in the wrapper class.

    I’d recommend adding timeStampPattern="yyyy-MM-dd" to your config. The code works without it’just easier to find the required log file.

    The code:

    `

        private static string _loggingOutputFileName;
        private static string _loggingRollFileFormat;
    
        public static void StartNewLogFile()
        {
            string fileName = LoggingOutputDirectory.Substring(0, LoggingOutputDirectory.LastIndexOf("\\")) + "\\" + _loggingOutputFileName;
    
            if (File.Exists(fileName))
            {
                string backupFileName;
                int fileIncrement = 1;
    
                while (true)
                {
                    backupFileName = LoggingOutputDirectory.Substring(0, LoggingOutputDirectory.LastIndexOf("\\")) + "\\" + _loggingOutputFileName.Insert(_loggingOutputFileName.LastIndexOf('.'), "." + DateTime.Now.ToString(_loggingRollFileFormat) + "." + fileIncrement);
                    if (!File.Exists(backupFileName))
                    {
                        break;
                    }
    
                    fileIncrement++;
                }
    
                File.Move(fileName, backupFileName);
            }
        }
    
        /// <summary>
        /// Gets the logging output from the app.config (loggingConfiguration section)
        /// </summary>
        private static void GetLoggingSettings()
        {
            IConfigurationSource configSource = ConfigurationSourceFactory.Create();
    
            LoggingSettings logSettings = LoggingSettings.GetLoggingSettings(configSource);
    
            TraceListenerDataCollection dataCollection = logSettings.TraceListeners;
    
            if (dataCollection.Count == 0)
                return;
    
            TraceListenerData traceListenerData = dataCollection.Get(0);
    
            if (traceListenerData is RollingFlatFileTraceListenerData)
            {
                RollingFlatFileTraceListenerData tld = (RollingFlatFileTraceListenerData)traceListenerData;
                _loggingOutputFileName = tld.FileName;
                _loggingRollFileFormat = tld.TimeStampPattern;
            }
        }
    
        private static string LoggingOutputDirectory
        {
            get
            {
                // Retrieve the logging settings on first call
                if (_loggingOutputFileName == null)
                    GetLoggingSettings();
    
                // Guard against null dereference
                if (_loggingOutputFileName == null)
                    return null;
    
                // Get the directory name for logging output
                FileInfo fileInfo = new FileInfo(_loggingOutputFileName);
                return fileInfo.DirectoryName;
            }
        }
    

    `

    Hope this helps.

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

Sidebar

Related Questions

Starting a new project and would like to use one of the MVC framworks.
I have this function that loads an specific .log file: function loadTracks():void { tracksLoader.load(new
I would like to give a class a unique ID every time a new
I would like something that I can use as follows var msg = new
I'm new to .NET and I would like to participate with .NET community to
I am new with Linq and I would like to sort some data that
I would like my program to update itself (downloading a new exe and/or some
I am still new to sharepoint and would like to know if it is
I'm fairly new to the world of versioning but would like to introduce Subversion
I am relatively new to using jQuery and would like to use the load

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.