Adding null check for logging config file name. Using complete filename for logging file suffix dictionary. Adding logging message on log file attempt fail.

--HG--
branch : 1.x
This commit is contained in:
Andre Rodrigues
2011-05-09 14:16:04 -07:00
parent 9d95dd542d
commit 797a7a2261
3 changed files with 14 additions and 10 deletions

View File

@@ -30,14 +30,14 @@ namespace Orchard.Tests.Caching {
[Test]
public void ComponentsAtHostLevelHaveAccessToCache() {
var alpha = _hostContainer.Resolve<Alpha>();
Assert.That(alpha.CacheManager, Is.Not.Null);
Assert.That(alpha.CacheManager, Is.Not.Null);
}
[Test]
public void HostLevelHasAccessToGlobalVolatileProviders() {
Assert.That(_hostContainer.Resolve<IWebSiteFolder>(), Is.Not.Null);
Assert.That(_hostContainer.Resolve<IAppDataFolder>(), Is.Not.Null);
Assert.That(_hostContainer.Resolve<IClock>(), Is.Not.Null);
Assert.That(_hostContainer.Resolve<IWebSiteFolder>(), Is.Not.Null);
Assert.That(_hostContainer.Resolve<IAppDataFolder>(), Is.Not.Null);
Assert.That(_hostContainer.Resolve<IClock>(), Is.Not.Null);
}
}

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic;
using log4net.Appender;
using log4net.Util;
namespace Orchard.Logging {
public class OrchardFileAppender : RollingFileAppender {
@@ -18,13 +19,14 @@ namespace Orchard.Logging {
protected override void OpenFile(string fileName, bool append) {
lock (this) {
bool fileOpened = false;
string completeFilename = GetNextOutputFileName(fileName);
string currentFilename = fileName;
if (!_suffixes.ContainsKey(fileName)) {
_suffixes[fileName] = 0;
if (!_suffixes.ContainsKey(completeFilename)) {
_suffixes[completeFilename] = 0;
}
int newSuffix = _suffixes[fileName];
int newSuffix = _suffixes[completeFilename];
for (int i = 1; !fileOpened && i <= Retries; i++) {
try {
@@ -36,11 +38,13 @@ namespace Orchard.Logging {
fileOpened = true;
} catch {
newSuffix = _suffixes[fileName] + i;
newSuffix = _suffixes[completeFilename] + i;
LogLog.Error(string.Format("OrchardFileAppender: Failed to open [{0}]. Attempting [{1}-{2}] instead.", fileName, fileName, newSuffix));
}
}
_suffixes[fileName] = newSuffix;
_suffixes[completeFilename] = newSuffix;
}
}

View File

@@ -11,7 +11,7 @@ namespace Orchard.Logging {
: this(ConfigurationManager.AppSettings["log4net.Config"], hostEnvironment) { }
public OrchardLog4netFactory(string configFilename, IHostEnvironment hostEnvironment) {
if (hostEnvironment.IsFullTrust) {
if (!string.IsNullOrWhiteSpace(configFilename) && hostEnvironment.IsFullTrust) {
// Only monitor configuration file in full trust
XmlConfigurator.ConfigureAndWatch(GetConfigFile(configFilename));
}