mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user