From 954dd2ef90ac7d715aa55cf0407321c49fdf0ff4 Mon Sep 17 00:00:00 2001 From: Andre Rodrigues Date: Mon, 9 May 2011 20:36:56 -0700 Subject: [PATCH] Clearing suffixes dictionary when a threshold is hit to avoid memory starvation. Adding further method header comments. --HG-- branch : 1.x --- src/Orchard/Logging/OrchardFileAppender.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Orchard/Logging/OrchardFileAppender.cs b/src/Orchard/Logging/OrchardFileAppender.cs index 08a8fae6f..1af9d2d79 100644 --- a/src/Orchard/Logging/OrchardFileAppender.cs +++ b/src/Orchard/Logging/OrchardFileAppender.cs @@ -9,8 +9,16 @@ namespace Orchard.Logging { /// private static readonly Dictionary _suffixes = new Dictionary(); + /// + /// The number of suffix attempts that will be made on each OpenFile method call. + /// private const int Retries = 50; + /// + /// Maximum number of suffixes recorded before a cleanup happens to recycle memory. + /// + private const int MaxSuffixes = 100; + /// /// Opens the log file adding an incremental suffix to the filename if required due to an openning failure (usually, locking). /// @@ -22,6 +30,10 @@ namespace Orchard.Logging { string completeFilename = GetNextOutputFileName(fileName); string currentFilename = fileName; + if (_suffixes.Count > MaxSuffixes) { + _suffixes.Clear(); + } + if (!_suffixes.ContainsKey(completeFilename)) { _suffixes[completeFilename] = 0; } @@ -48,6 +60,11 @@ namespace Orchard.Logging { } } + /// + /// Calls the base class OpenFile method. Allows this method to be mocked. + /// + /// The filename as specified in the configuration file. + /// Boolean flag indicating weather the log file should be appended if it already exists. protected virtual void BaseOpenFile(string fileName, bool append) { base.OpenFile(fileName, append); }