Clearing suffixes dictionary when a threshold is hit to avoid memory starvation. Adding further method header comments.

--HG--
branch : 1.x
This commit is contained in:
Andre Rodrigues
2011-05-09 20:36:56 -07:00
parent eddf71bcd1
commit 954dd2ef90

View File

@@ -9,8 +9,16 @@ namespace Orchard.Logging {
/// </summary>
private static readonly Dictionary<string, int> _suffixes = new Dictionary<string, int>();
/// <summary>
/// The number of suffix attempts that will be made on each OpenFile method call.
/// </summary>
private const int Retries = 50;
/// <summary>
/// Maximum number of suffixes recorded before a cleanup happens to recycle memory.
/// </summary>
private const int MaxSuffixes = 100;
/// <summary>
/// Opens the log file adding an incremental suffix to the filename if required due to an openning failure (usually, locking).
/// </summary>
@@ -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 {
}
}
/// <summary>
/// Calls the base class OpenFile method. Allows this method to be mocked.
/// </summary>
/// <param name="fileName">The filename as specified in the configuration file.</param>
/// <param name="append">Boolean flag indicating weather the log file should be appended if it already exists.</param>
protected virtual void BaseOpenFile(string fileName, bool append) {
base.OpenFile(fileName, append);
}