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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:51:17+00:00 2026-05-27T07:51:17+00:00

I Want to configure Enterprise Library Logger to write to a file until it

  • 0

I Want to configure Enterprise Library Logger to write to a file until it reaches a specified size.
After i reaches the specified size I would like it to do one of the following:

  • Do roll the file (Delete old log lines and add new ones, not the clear the entire file).
  • Keep the content in a file and clear the log file (keep only one backup file).

Currently I have configuration for one file that clears every time the file is full. This is my configuration

<listeners>
  <add fileName="C:\ProgramData\Hamoub\Log\TransferLog.log" 
       formatter="Text Formatter" 
       header="----------------------------------------"
       rollFileExistsBehavior="Overwrite" 
       rollSizeKB="100000" 
       listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       traceOutputOptions="None" 
       filter="All" 
       type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       name="Rolling Flat File Trace Listener"/>
</listeners>

Thanks for your help

  • 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-27T07:51:18+00:00Added an answer on May 27, 2026 at 7:51 am

    So, There is no way to do this in configuration alone.
    My solution was to add FileSystemWatcher on the output folder, and whenever a new file is created there, I checked if deletion is needed.
    I have ordered the folder files before deletion so only old files will be deleted (keeping the current and previous log files.

    The Watcher Code:

            try
            {
                FileSystemWatcher fsw = new FileSystemWatcher(@"C:\ProgramData\Hamoub\Log");
                fsw.EnableRaisingEvents = true;
                fsw.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite |
                       NotifyFilters.DirectoryName | NotifyFilters.FileName;
                fsw.Created += new FileSystemEventHandler(FileCreatedOnLogFolder);
            }
            catch (Exception ex)
            {
                Logger.Log("Failed creating file system watcher: " + ex.Message, Severity.Warning);
            }
    

    The handler Code:

        void FileCreatedOnLogFolder(object sender, FileSystemEventArgs e)
        {
            try
            {
                DirectoryInfo logsDir = new DirectoryInfo(@"C:\ProgramData\Hamoub\Log");
                var logFiles = logsDir.GetFiles("*TransferServiceTrace*.log");
                var orderedLogFiles = logFiles.OrderBy(e => e.CreationTime);
    
                if (orderedLogFiles.Count() > 1)
                {
                    Logger.Log("Maintenance is needed, More than 2 log files found", Severity.Verbose);
                    for (int i = 0; i < orderedLogFiles.Count() - 2; i++)
                    {
                        try
                        {
                            var toDeleteFile = (orderedLogFiles.ElementAt(i) as FileInfo);
                            if (toDeleteFile != null)
                            {
                                toDeleteFile.Delete();
                            }
                        }
                        catch (Exception)
                        {
                            Logger.Log("Can't delete log file " + (orderedLogFiles.ElementAt(i) as FileInfo).Name, Severity.Warning);
                        }
                    }
                    // Store last file as TransferService.Last.Log
                    (orderedLogFiles.ElementAt(orderedLogFiles.Count() - 2) as FileInfo).CopyTo(Path.Combine(logsDir.FullName, "TransferService.Last.Log"), true);
                    (orderedLogFiles.ElementAt(orderedLogFiles.Count() - 2) as FileInfo).Delete();
                }
            }
            catch (Exception ex)
            {
                Logger.Log("Error during folder maintenance. " + ex.Message, Severity.Warning);
            }
        }
    

    Hopefully, this post will help someone who looks for such solution

    Barak Hamou

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

Sidebar

Related Questions

I want to configure the tree view component so that would be the topmost
I have an xml file that I want to configure using a bash script.
I want to create an external js-file, in which I can configure the copy
I want to configure a bigger pool size for my message consumer in my
I want to configure my Python logger in such a way so that each
In the filesystem I have /file.aspx /directory/default.aspx I want to configure IIS so that
I want to configure a property in my properties file. But that will not
I want to configure IIS 7 logging options (log file format, request fields included,
I want to configure Emacs so that it has: Increased default font size. Currently
I want to configure product like this,when a customer puts his order he can

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.