mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-22 03:37:25 +08:00
Log4net configuration updated to use date based rolling file (and exclude time portion from filename).
Bugfix related code formatting done on new files. --HG-- branch : contributions
This commit is contained in:
@@ -54,7 +54,7 @@
|
|||||||
<staticLogFileName value="false" />
|
<staticLogFileName value="false" />
|
||||||
<rollingStyle value="Date" />
|
<rollingStyle value="Date" />
|
||||||
<rollingStyleFrequency value="Once" />
|
<rollingStyleFrequency value="Once" />
|
||||||
<datepattern value="-dd.MM.yyyy-hh_mm_ss.fff'.log'" />
|
<datepattern value="-dd.MM.yyyy'.log'" />
|
||||||
|
|
||||||
<layout type="log4net.Layout.PatternLayout">
|
<layout type="log4net.Layout.PatternLayout">
|
||||||
<conversionPattern value="%date [%thread] %logger - %message%newline" />
|
<conversionPattern value="%date [%thread] %logger - %message%newline" />
|
||||||
@@ -73,7 +73,7 @@
|
|||||||
<staticLogFileName value="false" />
|
<staticLogFileName value="false" />
|
||||||
<rollingStyle value="Date" />
|
<rollingStyle value="Date" />
|
||||||
<rollingStyleFrequency value="Once" />
|
<rollingStyleFrequency value="Once" />
|
||||||
<datepattern value="-dd.MM.yyyy-hh_mm_ss.fff'.log'" />
|
<datepattern value="-dd.MM.yyyy'.log'" />
|
||||||
|
|
||||||
<filter type="log4net.Filter.LevelRangeFilter">
|
<filter type="log4net.Filter.LevelRangeFilter">
|
||||||
<!-- only error and fatal messages end up in this target, even if child loggers accept lower priority -->
|
<!-- only error and fatal messages end up in this target, even if child loggers accept lower priority -->
|
||||||
|
@@ -195,17 +195,7 @@
|
|||||||
<VisualStudio>
|
<VisualStudio>
|
||||||
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
|
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
|
||||||
<WebProjectProperties>
|
<WebProjectProperties>
|
||||||
<UseIIS>False</UseIIS>
|
<SaveServerSettingsInUserFile>True</SaveServerSettingsInUserFile>
|
||||||
<AutoAssignPort>False</AutoAssignPort>
|
|
||||||
<DevelopmentServerPort>30320</DevelopmentServerPort>
|
|
||||||
<DevelopmentServerVPath>/OrchardLocal</DevelopmentServerVPath>
|
|
||||||
<IISUrl>
|
|
||||||
</IISUrl>
|
|
||||||
<NTLMAuthentication>False</NTLMAuthentication>
|
|
||||||
<UseCustomServer>False</UseCustomServer>
|
|
||||||
<CustomServerUrl>
|
|
||||||
</CustomServerUrl>
|
|
||||||
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
|
|
||||||
</WebProjectProperties>
|
</WebProjectProperties>
|
||||||
</FlavorProperties>
|
</FlavorProperties>
|
||||||
</VisualStudio>
|
</VisualStudio>
|
||||||
|
@@ -5,12 +5,8 @@ using System.Web;
|
|||||||
using System.Web.Hosting;
|
using System.Web.Hosting;
|
||||||
|
|
||||||
using Castle.Core.Logging;
|
using Castle.Core.Logging;
|
||||||
using Castle.Services.Logging.Log4netIntegration;
|
|
||||||
|
|
||||||
using log4net;
|
using log4net;
|
||||||
using log4net.Config;
|
|
||||||
|
|
||||||
using Orchard.Environment.Extensions.Helpers;
|
|
||||||
|
|
||||||
namespace Orchard.Logging {
|
namespace Orchard.Logging {
|
||||||
public class OrchardLog4netFactory : AbstractLoggerFactory {
|
public class OrchardLog4netFactory : AbstractLoggerFactory {
|
||||||
|
@@ -1,20 +1,15 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Xml;
|
|
||||||
using System.Collections;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading;
|
using System.Xml;
|
||||||
using System.Net;
|
|
||||||
|
|
||||||
using log4net;
|
using log4net;
|
||||||
using log4net.Appender;
|
|
||||||
using log4net.Util;
|
|
||||||
using log4net.Repository;
|
using log4net.Repository;
|
||||||
using log4net.Repository.Hierarchy;
|
using log4net.Repository.Hierarchy;
|
||||||
|
using log4net.Util;
|
||||||
|
|
||||||
namespace Orchard.Logging {
|
namespace Orchard.Logging {
|
||||||
public class OrchardXmlConfigurator {
|
public class OrchardXmlConfigurator {
|
||||||
#region Private Instance Constructors
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Private constructor
|
/// Private constructor
|
||||||
@@ -22,10 +17,6 @@ namespace Orchard.Logging {
|
|||||||
private OrchardXmlConfigurator() {
|
private OrchardXmlConfigurator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Protected Instance Constructors
|
|
||||||
|
|
||||||
#region Configure static methods
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Configures log4net using the specified configuration file.
|
/// Configures log4net using the specified configuration file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -76,7 +67,7 @@ namespace Orchard.Logging {
|
|||||||
/// </configuration>
|
/// </configuration>
|
||||||
/// </code>
|
/// </code>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
static public void Configure(string configFilename) {
|
public static void Configure(string configFilename) {
|
||||||
Configure(LogManager.GetRepository(Assembly.GetCallingAssembly()), configFilename);
|
Configure(LogManager.GetRepository(Assembly.GetCallingAssembly()), configFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +85,7 @@ namespace Orchard.Logging {
|
|||||||
/// Note that this method will NOT close the stream parameter.
|
/// Note that this method will NOT close the stream parameter.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
static public void Configure(Stream configStream) {
|
public static void Configure(Stream configStream) {
|
||||||
Configure(LogManager.GetRepository(Assembly.GetCallingAssembly()), configStream);
|
Configure(LogManager.GetRepository(Assembly.GetCallingAssembly()), configStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,7 +141,7 @@ namespace Orchard.Logging {
|
|||||||
/// </configuration>
|
/// </configuration>
|
||||||
/// </code>
|
/// </code>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
static public void Configure(ILoggerRepository repository, string configFilename) {
|
public static void Configure(ILoggerRepository repository, string configFilename) {
|
||||||
LogLog.Debug("XmlConfigurator: configuring repository [" + repository.Name + "] using file [" + configFilename + "]");
|
LogLog.Debug("XmlConfigurator: configuring repository [" + repository.Name + "] using file [" + configFilename + "]");
|
||||||
|
|
||||||
if (String.IsNullOrWhiteSpace(configFilename)) {
|
if (String.IsNullOrWhiteSpace(configFilename)) {
|
||||||
@@ -214,7 +205,7 @@ namespace Orchard.Logging {
|
|||||||
/// Note that this method will NOT close the stream parameter.
|
/// Note that this method will NOT close the stream parameter.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
static public void Configure(ILoggerRepository repository, Stream configStream) {
|
public static void Configure(ILoggerRepository repository, Stream configStream) {
|
||||||
LogLog.Debug("XmlConfigurator: configuring repository [" + repository.Name + "] using stream");
|
LogLog.Debug("XmlConfigurator: configuring repository [" + repository.Name + "] using stream");
|
||||||
|
|
||||||
if (configStream == null) {
|
if (configStream == null) {
|
||||||
@@ -260,10 +251,6 @@ namespace Orchard.Logging {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Configure static methods
|
|
||||||
|
|
||||||
#region Private Static Methods
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Configures the specified repository using a <c>log4net</c> element.
|
/// Configures the specified repository using a <c>log4net</c> element.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -279,7 +266,7 @@ namespace Orchard.Logging {
|
|||||||
/// to load the configuration from an <see cref="XmlElement"/>.
|
/// to load the configuration from an <see cref="XmlElement"/>.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
static private void ConfigureFromXml(ILoggerRepository repository, XmlElement element) {
|
private static void ConfigureFromXml(ILoggerRepository repository, XmlElement element) {
|
||||||
if (element == null) {
|
if (element == null) {
|
||||||
LogLog.Error("XmlConfigurator: ConfigureFromXml called with null 'element' parameter");
|
LogLog.Error("XmlConfigurator: ConfigureFromXml called with null 'element' parameter");
|
||||||
}
|
}
|
||||||
@@ -319,7 +306,5 @@ namespace Orchard.Logging {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Private Static Methods
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,10 +5,10 @@ using System.Reflection;
|
|||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
|
||||||
using log4net.Appender;
|
using log4net.Appender;
|
||||||
using log4net.Util;
|
|
||||||
using log4net.Core;
|
using log4net.Core;
|
||||||
using log4net.ObjectRenderer;
|
using log4net.ObjectRenderer;
|
||||||
using log4net.Repository.Hierarchy;
|
using log4net.Repository.Hierarchy;
|
||||||
|
using log4net.Util;
|
||||||
|
|
||||||
namespace Orchard.Logging {
|
namespace Orchard.Logging {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -27,7 +27,50 @@ namespace Orchard.Logging {
|
|||||||
Overwrite
|
Overwrite
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Public Instance Constructors
|
// String constants used while parsing the XML data
|
||||||
|
private const string ConfigurationTag = "log4net";
|
||||||
|
private const string RendererTag = "renderer";
|
||||||
|
private const string AppenderTag = "appender";
|
||||||
|
private const string AppenderRefTag = "appender-ref";
|
||||||
|
private const string ParamTag = "param";
|
||||||
|
|
||||||
|
// TODO: Deprecate use of category tags
|
||||||
|
private const string CategoryTag = "category";
|
||||||
|
// TODO: Deprecate use of priority tag
|
||||||
|
private const string PriorityTag = "priority";
|
||||||
|
|
||||||
|
private const string LoggerTag = "logger";
|
||||||
|
private const string NameAttr = "name";
|
||||||
|
private const string TypeAttr = "type";
|
||||||
|
private const string ValueAttr = "value";
|
||||||
|
private const string RootTag = "root";
|
||||||
|
private const string LevelTag = "level";
|
||||||
|
private const string RefAttr = "ref";
|
||||||
|
private const string AdditivityAttr = "additivity";
|
||||||
|
private const string ThresholdAttr = "threshold";
|
||||||
|
private const string ConfigDebugAttr = "configDebug";
|
||||||
|
private const string InternalDebugAttr = "debug";
|
||||||
|
private const string ConfigUpdateModeAttr = "update";
|
||||||
|
private const string RenderingTypeAttr = "renderingClass";
|
||||||
|
private const string RenderedTypeAttr = "renderedClass";
|
||||||
|
|
||||||
|
// flag used on the level element
|
||||||
|
private const string Inherited = "inherited";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// key: appenderName, value: appender.
|
||||||
|
/// </summary>
|
||||||
|
private Hashtable _appenderBag;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Hierarchy being configured.
|
||||||
|
/// </summary>
|
||||||
|
private readonly Hierarchy _hierarchy;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The snapshot of the environment variables at configuration time, or null if an error has occured during querying them.
|
||||||
|
/// </summary>
|
||||||
|
private IDictionary _environmentVariables;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Construct the configurator for a hierarchy
|
/// Construct the configurator for a hierarchy
|
||||||
@@ -40,14 +83,10 @@ namespace Orchard.Logging {
|
|||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public OrchardXmlHierarchyConfigurator(Hierarchy hierarchy) {
|
public OrchardXmlHierarchyConfigurator(Hierarchy hierarchy) {
|
||||||
m_hierarchy = hierarchy;
|
_hierarchy = hierarchy;
|
||||||
m_appenderBag = new Hashtable();
|
_appenderBag = new Hashtable();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Public Instance Constructors
|
|
||||||
|
|
||||||
#region Public Instance Methods
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Configure the hierarchy by parsing a DOM tree of XML elements.
|
/// Configure the hierarchy by parsing a DOM tree of XML elements.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -58,33 +97,33 @@ namespace Orchard.Logging {
|
|||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public void Configure(XmlElement element) {
|
public void Configure(XmlElement element) {
|
||||||
if (element == null || m_hierarchy == null) {
|
if (element == null || _hierarchy == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string rootElementName = element.LocalName;
|
string rootElementName = element.LocalName;
|
||||||
|
|
||||||
if (rootElementName != CONFIGURATION_TAG) {
|
if (rootElementName != ConfigurationTag) {
|
||||||
LogLog.Error("XmlHierarchyConfigurator: Xml element is - not a <" + CONFIGURATION_TAG + "> element.");
|
LogLog.Error("XmlHierarchyConfigurator: Xml element is - not a <" + ConfigurationTag + "> element.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!LogLog.InternalDebugging) {
|
if (!LogLog.InternalDebugging) {
|
||||||
// Look for a debug attribute to enable internal debug
|
// Look for a debug attribute to enable internal debug
|
||||||
string debugAttribute = element.GetAttribute(INTERNAL_DEBUG_ATTR);
|
string debugAttribute = element.GetAttribute(InternalDebugAttr);
|
||||||
LogLog.Debug("XmlHierarchyConfigurator: " + INTERNAL_DEBUG_ATTR + " attribute [" + debugAttribute + "].");
|
LogLog.Debug("XmlHierarchyConfigurator: " + InternalDebugAttr + " attribute [" + debugAttribute + "].");
|
||||||
|
|
||||||
if (debugAttribute.Length > 0 && debugAttribute != "null") {
|
if (debugAttribute.Length > 0 && debugAttribute != "null") {
|
||||||
LogLog.InternalDebugging = OptionConverter.ToBoolean(debugAttribute, true);
|
LogLog.InternalDebugging = OptionConverter.ToBoolean(debugAttribute, true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LogLog.Debug("XmlHierarchyConfigurator: Ignoring " + INTERNAL_DEBUG_ATTR + " attribute.");
|
LogLog.Debug("XmlHierarchyConfigurator: Ignoring " + InternalDebugAttr + " attribute.");
|
||||||
}
|
}
|
||||||
|
|
||||||
string confDebug = element.GetAttribute(CONFIG_DEBUG_ATTR);
|
string confDebug = element.GetAttribute(ConfigDebugAttr);
|
||||||
if (confDebug.Length > 0 && confDebug != "null") {
|
if (confDebug.Length > 0 && confDebug != "null") {
|
||||||
LogLog.Warn("XmlHierarchyConfigurator: The \"" + CONFIG_DEBUG_ATTR + "\" attribute is deprecated.");
|
LogLog.Warn("XmlHierarchyConfigurator: The \"" + ConfigDebugAttr + "\" attribute is deprecated.");
|
||||||
LogLog.Warn("XmlHierarchyConfigurator: Use the \"" + INTERNAL_DEBUG_ATTR + "\" attribute instead.");
|
LogLog.Warn("XmlHierarchyConfigurator: Use the \"" + InternalDebugAttr + "\" attribute instead.");
|
||||||
LogLog.InternalDebugging = OptionConverter.ToBoolean(confDebug, true);
|
LogLog.InternalDebugging = OptionConverter.ToBoolean(confDebug, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,14 +132,14 @@ namespace Orchard.Logging {
|
|||||||
ConfigUpdateMode configUpdateMode = ConfigUpdateMode.Merge;
|
ConfigUpdateMode configUpdateMode = ConfigUpdateMode.Merge;
|
||||||
|
|
||||||
// Look for the config update attribute
|
// Look for the config update attribute
|
||||||
string configUpdateModeAttribute = element.GetAttribute(CONFIG_UPDATE_MODE_ATTR);
|
string configUpdateModeAttribute = element.GetAttribute(ConfigUpdateModeAttr);
|
||||||
if (configUpdateModeAttribute != null && configUpdateModeAttribute.Length > 0) {
|
if (configUpdateModeAttribute != null && configUpdateModeAttribute.Length > 0) {
|
||||||
// Parse the attribute
|
// Parse the attribute
|
||||||
try {
|
try {
|
||||||
configUpdateMode = (ConfigUpdateMode)OptionConverter.ConvertStringTo(typeof(ConfigUpdateMode), configUpdateModeAttribute);
|
configUpdateMode = (ConfigUpdateMode)OptionConverter.ConvertStringTo(typeof(ConfigUpdateMode), configUpdateModeAttribute);
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
LogLog.Error("XmlHierarchyConfigurator: Invalid " + CONFIG_UPDATE_MODE_ATTR + " attribute value [" + configUpdateModeAttribute + "]");
|
LogLog.Error("XmlHierarchyConfigurator: Invalid " + ConfigUpdateModeAttr + " attribute value [" + configUpdateModeAttribute + "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,16 +149,16 @@ namespace Orchard.Logging {
|
|||||||
// Only reset configuration if overwrite flag specified
|
// Only reset configuration if overwrite flag specified
|
||||||
if (configUpdateMode == ConfigUpdateMode.Overwrite) {
|
if (configUpdateMode == ConfigUpdateMode.Overwrite) {
|
||||||
// Reset to original unset configuration
|
// Reset to original unset configuration
|
||||||
m_hierarchy.ResetConfiguration();
|
_hierarchy.ResetConfiguration();
|
||||||
LogLog.Debug("XmlHierarchyConfigurator: Configuration reset before reading config.");
|
LogLog.Debug("XmlHierarchyConfigurator: Configuration reset before reading config.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to retrieve the environment variables
|
// Try to retrieve the environment variables
|
||||||
try {
|
try {
|
||||||
m_environmentVariables = System.Environment.GetEnvironmentVariables();
|
_environmentVariables = System.Environment.GetEnvironmentVariables();
|
||||||
}
|
}
|
||||||
catch (System.Security.SecurityException) {
|
catch (System.Security.SecurityException) {
|
||||||
m_environmentVariables = null;
|
_environmentVariables = null;
|
||||||
|
|
||||||
// This security exception will occur if the caller does not have
|
// This security exception will occur if the caller does not have
|
||||||
// unrestricted environment permission. If this occurs the expansion
|
// unrestricted environment permission. If this occurs the expansion
|
||||||
@@ -136,37 +175,37 @@ namespace Orchard.Logging {
|
|||||||
if (currentNode.NodeType == XmlNodeType.Element) {
|
if (currentNode.NodeType == XmlNodeType.Element) {
|
||||||
XmlElement currentElement = (XmlElement)currentNode;
|
XmlElement currentElement = (XmlElement)currentNode;
|
||||||
|
|
||||||
if (currentElement.LocalName == LOGGER_TAG) {
|
if (currentElement.LocalName == LoggerTag) {
|
||||||
ParseLogger(currentElement);
|
ParseLogger(currentElement);
|
||||||
}
|
}
|
||||||
else if (currentElement.LocalName == CATEGORY_TAG) {
|
else if (currentElement.LocalName == CategoryTag) {
|
||||||
// TODO: deprecated use of category
|
// TODO: deprecated use of category
|
||||||
ParseLogger(currentElement);
|
ParseLogger(currentElement);
|
||||||
}
|
}
|
||||||
else if (currentElement.LocalName == ROOT_TAG) {
|
else if (currentElement.LocalName == RootTag) {
|
||||||
ParseRoot(currentElement);
|
ParseRoot(currentElement);
|
||||||
}
|
}
|
||||||
else if (currentElement.LocalName == RENDERER_TAG) {
|
else if (currentElement.LocalName == RendererTag) {
|
||||||
ParseRenderer(currentElement);
|
ParseRenderer(currentElement);
|
||||||
}
|
}
|
||||||
else if (currentElement.LocalName == APPENDER_TAG) {
|
else if (currentElement.LocalName == AppenderTag) {
|
||||||
// We ignore appenders in this pass. They will
|
// We ignore appenders in this pass. They will
|
||||||
// be found and loaded if they are referenced.
|
// be found and loaded if they are referenced.
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Read the param tags and set properties on the hierarchy
|
// Read the param tags and set properties on the hierarchy
|
||||||
SetParameter(currentElement, m_hierarchy);
|
SetParameter(currentElement, _hierarchy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lastly set the hierarchy threshold
|
// Lastly set the hierarchy threshold
|
||||||
string thresholdStr = element.GetAttribute(THRESHOLD_ATTR);
|
string thresholdStr = element.GetAttribute(ThresholdAttr);
|
||||||
LogLog.Debug("XmlHierarchyConfigurator: Hierarchy Threshold [" + thresholdStr + "]");
|
LogLog.Debug("XmlHierarchyConfigurator: Hierarchy Threshold [" + thresholdStr + "]");
|
||||||
if (thresholdStr.Length > 0 && thresholdStr != "null") {
|
if (thresholdStr.Length > 0 && thresholdStr != "null") {
|
||||||
Level thresholdLevel = (Level)ConvertStringTo(typeof(Level), thresholdStr);
|
Level thresholdLevel = (Level)ConvertStringTo(typeof(Level), thresholdStr);
|
||||||
if (thresholdLevel != null) {
|
if (thresholdLevel != null) {
|
||||||
m_hierarchy.Threshold = thresholdLevel;
|
_hierarchy.Threshold = thresholdLevel;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LogLog.Warn("XmlHierarchyConfigurator: Unable to set hierarchy threshold using value [" + thresholdStr + "] (with acceptable conversion types)");
|
LogLog.Warn("XmlHierarchyConfigurator: Unable to set hierarchy threshold using value [" + thresholdStr + "] (with acceptable conversion types)");
|
||||||
@@ -176,10 +215,6 @@ namespace Orchard.Logging {
|
|||||||
// Done reading config
|
// Done reading config
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Public Instance Methods
|
|
||||||
|
|
||||||
#region Protected Instance Methods
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parse appenders by IDREF.
|
/// Parse appenders by IDREF.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -192,9 +227,9 @@ namespace Orchard.Logging {
|
|||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
protected IAppender FindAppenderByReference(XmlElement appenderRef) {
|
protected IAppender FindAppenderByReference(XmlElement appenderRef) {
|
||||||
string appenderName = appenderRef.GetAttribute(REF_ATTR);
|
string appenderName = appenderRef.GetAttribute(RefAttr);
|
||||||
|
|
||||||
IAppender appender = (IAppender)m_appenderBag[appenderName];
|
IAppender appender = (IAppender)_appenderBag[appenderName];
|
||||||
if (appender != null) {
|
if (appender != null) {
|
||||||
return appender;
|
return appender;
|
||||||
}
|
}
|
||||||
@@ -203,7 +238,7 @@ namespace Orchard.Logging {
|
|||||||
XmlElement element = null;
|
XmlElement element = null;
|
||||||
|
|
||||||
if (appenderName != null && appenderName.Length > 0) {
|
if (appenderName != null && appenderName.Length > 0) {
|
||||||
foreach (XmlElement curAppenderElement in appenderRef.OwnerDocument.GetElementsByTagName(APPENDER_TAG)) {
|
foreach (XmlElement curAppenderElement in appenderRef.OwnerDocument.GetElementsByTagName(AppenderTag)) {
|
||||||
if (curAppenderElement.GetAttribute("name") == appenderName) {
|
if (curAppenderElement.GetAttribute("name") == appenderName) {
|
||||||
element = curAppenderElement;
|
element = curAppenderElement;
|
||||||
break;
|
break;
|
||||||
@@ -218,7 +253,7 @@ namespace Orchard.Logging {
|
|||||||
else {
|
else {
|
||||||
appender = ParseAppender(element);
|
appender = ParseAppender(element);
|
||||||
if (appender != null) {
|
if (appender != null) {
|
||||||
m_appenderBag[appenderName] = appender;
|
_appenderBag[appenderName] = appender;
|
||||||
}
|
}
|
||||||
return appender;
|
return appender;
|
||||||
}
|
}
|
||||||
@@ -237,8 +272,8 @@ namespace Orchard.Logging {
|
|||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
protected IAppender ParseAppender(XmlElement appenderElement) {
|
protected IAppender ParseAppender(XmlElement appenderElement) {
|
||||||
string appenderName = appenderElement.GetAttribute(NAME_ATTR);
|
string appenderName = appenderElement.GetAttribute(NameAttr);
|
||||||
string typeName = appenderElement.GetAttribute(TYPE_ATTR);
|
string typeName = appenderElement.GetAttribute(TypeAttr);
|
||||||
|
|
||||||
LogLog.Debug("XmlHierarchyConfigurator: Loading Appender [" + appenderName + "] type: [" + typeName + "]");
|
LogLog.Debug("XmlHierarchyConfigurator: Loading Appender [" + appenderName + "] type: [" + typeName + "]");
|
||||||
try {
|
try {
|
||||||
@@ -251,8 +286,8 @@ namespace Orchard.Logging {
|
|||||||
XmlElement currentElement = (XmlElement)currentNode;
|
XmlElement currentElement = (XmlElement)currentNode;
|
||||||
|
|
||||||
// Look for the appender ref tag
|
// Look for the appender ref tag
|
||||||
if (currentElement.LocalName == APPENDER_REF_TAG) {
|
if (currentElement.LocalName == AppenderRefTag) {
|
||||||
string refName = currentElement.GetAttribute(REF_ATTR);
|
string refName = currentElement.GetAttribute(RefAttr);
|
||||||
|
|
||||||
IAppenderAttachable appenderContainer = appender as IAppenderAttachable;
|
IAppenderAttachable appenderContainer = appender as IAppenderAttachable;
|
||||||
if (appenderContainer != null) {
|
if (appenderContainer != null) {
|
||||||
@@ -301,16 +336,16 @@ namespace Orchard.Logging {
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
protected void ParseLogger(XmlElement loggerElement) {
|
protected void ParseLogger(XmlElement loggerElement) {
|
||||||
// Create a new log4net.Logger object from the <logger> element.
|
// Create a new log4net.Logger object from the <logger> element.
|
||||||
string loggerName = loggerElement.GetAttribute(NAME_ATTR);
|
string loggerName = loggerElement.GetAttribute(NameAttr);
|
||||||
|
|
||||||
LogLog.Debug("XmlHierarchyConfigurator: Retrieving an instance of log4net.Repository.Logger for logger [" + loggerName + "].");
|
LogLog.Debug("XmlHierarchyConfigurator: Retrieving an instance of log4net.Repository.Logger for logger [" + loggerName + "].");
|
||||||
Logger log = m_hierarchy.GetLogger(loggerName) as Logger;
|
Logger log = _hierarchy.GetLogger(loggerName) as Logger;
|
||||||
|
|
||||||
// Setting up a logger needs to be an atomic operation, in order
|
// Setting up a logger needs to be an atomic operation, in order
|
||||||
// to protect potential log operations while logger
|
// to protect potential log operations while logger
|
||||||
// configuration is in progress.
|
// configuration is in progress.
|
||||||
lock (log) {
|
lock (log) {
|
||||||
bool additivity = OptionConverter.ToBoolean(loggerElement.GetAttribute(ADDITIVITY_ATTR), true);
|
bool additivity = OptionConverter.ToBoolean(loggerElement.GetAttribute(AdditivityAttr), true);
|
||||||
|
|
||||||
LogLog.Debug("XmlHierarchyConfigurator: Setting [" + log.Name + "] additivity to [" + additivity + "].");
|
LogLog.Debug("XmlHierarchyConfigurator: Setting [" + log.Name + "] additivity to [" + additivity + "].");
|
||||||
log.Additivity = additivity;
|
log.Additivity = additivity;
|
||||||
@@ -328,7 +363,7 @@ namespace Orchard.Logging {
|
|||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
protected void ParseRoot(XmlElement rootElement) {
|
protected void ParseRoot(XmlElement rootElement) {
|
||||||
Logger root = m_hierarchy.Root;
|
Logger root = _hierarchy.Root;
|
||||||
// logger configuration needs to be atomic
|
// logger configuration needs to be atomic
|
||||||
lock (root) {
|
lock (root) {
|
||||||
ParseChildrenOfLoggerElement(rootElement, root, true);
|
ParseChildrenOfLoggerElement(rootElement, root, true);
|
||||||
@@ -355,9 +390,9 @@ namespace Orchard.Logging {
|
|||||||
if (currentNode.NodeType == XmlNodeType.Element) {
|
if (currentNode.NodeType == XmlNodeType.Element) {
|
||||||
XmlElement currentElement = (XmlElement)currentNode;
|
XmlElement currentElement = (XmlElement)currentNode;
|
||||||
|
|
||||||
if (currentElement.LocalName == APPENDER_REF_TAG) {
|
if (currentElement.LocalName == AppenderRefTag) {
|
||||||
IAppender appender = FindAppenderByReference(currentElement);
|
IAppender appender = FindAppenderByReference(currentElement);
|
||||||
string refName = currentElement.GetAttribute(REF_ATTR);
|
string refName = currentElement.GetAttribute(RefAttr);
|
||||||
if (appender != null) {
|
if (appender != null) {
|
||||||
LogLog.Debug("XmlHierarchyConfigurator: Adding appender named [" + refName + "] to logger [" + log.Name + "].");
|
LogLog.Debug("XmlHierarchyConfigurator: Adding appender named [" + refName + "] to logger [" + log.Name + "].");
|
||||||
log.AddAppender(appender);
|
log.AddAppender(appender);
|
||||||
@@ -366,7 +401,7 @@ namespace Orchard.Logging {
|
|||||||
LogLog.Error("XmlHierarchyConfigurator: Appender named [" + refName + "] not found.");
|
LogLog.Error("XmlHierarchyConfigurator: Appender named [" + refName + "] not found.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (currentElement.LocalName == LEVEL_TAG || currentElement.LocalName == PRIORITY_TAG) {
|
else if (currentElement.LocalName == LevelTag || currentElement.LocalName == PriorityTag) {
|
||||||
ParseLevel(currentElement, log, isRoot);
|
ParseLevel(currentElement, log, isRoot);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -391,8 +426,8 @@ namespace Orchard.Logging {
|
|||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
protected void ParseRenderer(XmlElement element) {
|
protected void ParseRenderer(XmlElement element) {
|
||||||
string renderingClassName = element.GetAttribute(RENDERING_TYPE_ATTR);
|
string renderingClassName = element.GetAttribute(RenderingTypeAttr);
|
||||||
string renderedClassName = element.GetAttribute(RENDERED_TYPE_ATTR);
|
string renderedClassName = element.GetAttribute(RenderedTypeAttr);
|
||||||
|
|
||||||
LogLog.Debug("XmlHierarchyConfigurator: Rendering class [" + renderingClassName + "], Rendered class [" + renderedClassName + "].");
|
LogLog.Debug("XmlHierarchyConfigurator: Rendering class [" + renderingClassName + "], Rendered class [" + renderedClassName + "].");
|
||||||
IObjectRenderer renderer = (IObjectRenderer)OptionConverter.InstantiateByClassName(renderingClassName, typeof(IObjectRenderer), null);
|
IObjectRenderer renderer = (IObjectRenderer)OptionConverter.InstantiateByClassName(renderingClassName, typeof(IObjectRenderer), null);
|
||||||
@@ -402,7 +437,7 @@ namespace Orchard.Logging {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
m_hierarchy.RendererMap.Put(SystemInfo.GetTypeFromString(renderedClassName, true, true), renderer);
|
_hierarchy.RendererMap.Put(SystemInfo.GetTypeFromString(renderedClassName, true, true), renderer);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
LogLog.Error("XmlHierarchyConfigurator: Could not find class [" + renderedClassName + "].", e);
|
LogLog.Error("XmlHierarchyConfigurator: Could not find class [" + renderedClassName + "].", e);
|
||||||
@@ -427,10 +462,10 @@ namespace Orchard.Logging {
|
|||||||
loggerName = "root";
|
loggerName = "root";
|
||||||
}
|
}
|
||||||
|
|
||||||
string levelStr = element.GetAttribute(VALUE_ATTR);
|
string levelStr = element.GetAttribute(ValueAttr);
|
||||||
LogLog.Debug("XmlHierarchyConfigurator: Logger [" + loggerName + "] Level string is [" + levelStr + "].");
|
LogLog.Debug("XmlHierarchyConfigurator: Logger [" + loggerName + "] Level string is [" + levelStr + "].");
|
||||||
|
|
||||||
if (INHERITED == levelStr) {
|
if (Inherited == levelStr) {
|
||||||
if (isRoot) {
|
if (isRoot) {
|
||||||
LogLog.Error("XmlHierarchyConfigurator: Root level cannot be inherited. Ignoring directive.");
|
LogLog.Error("XmlHierarchyConfigurator: Root level cannot be inherited. Ignoring directive.");
|
||||||
}
|
}
|
||||||
@@ -468,10 +503,10 @@ namespace Orchard.Logging {
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
protected void SetParameter(XmlElement element, object target) {
|
protected void SetParameter(XmlElement element, object target) {
|
||||||
// Get the property name
|
// Get the property name
|
||||||
string name = element.GetAttribute(NAME_ATTR);
|
string name = element.GetAttribute(NameAttr);
|
||||||
|
|
||||||
// If the name attribute does not exist then use the name of the element
|
// If the name attribute does not exist then use the name of the element
|
||||||
if (element.LocalName != PARAM_TAG || name == null || name.Length == 0) {
|
if (element.LocalName != ParamTag || name == null || name.Length == 0) {
|
||||||
name = element.LocalName;
|
name = element.LocalName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -505,8 +540,8 @@ namespace Orchard.Logging {
|
|||||||
else {
|
else {
|
||||||
string propertyValue = null;
|
string propertyValue = null;
|
||||||
|
|
||||||
if (element.GetAttributeNode(VALUE_ATTR) != null) {
|
if (element.GetAttributeNode(ValueAttr) != null) {
|
||||||
propertyValue = element.GetAttribute(VALUE_ATTR);
|
propertyValue = element.GetAttribute(ValueAttr);
|
||||||
}
|
}
|
||||||
else if (element.HasChildNodes) {
|
else if (element.HasChildNodes) {
|
||||||
// Concatenate the CDATA and Text nodes together
|
// Concatenate the CDATA and Text nodes together
|
||||||
@@ -523,15 +558,15 @@ namespace Orchard.Logging {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (propertyValue != null) {
|
if (propertyValue != null) {
|
||||||
if (m_environmentVariables != null) {
|
if (_environmentVariables != null) {
|
||||||
// Expand environment variables in the string.
|
// Expand environment variables in the string.
|
||||||
propertyValue = OptionConverter.SubstituteVariables(propertyValue, m_environmentVariables);
|
propertyValue = OptionConverter.SubstituteVariables(propertyValue, _environmentVariables);
|
||||||
}
|
}
|
||||||
|
|
||||||
Type parsedObjectConversionTargetType = null;
|
Type parsedObjectConversionTargetType = null;
|
||||||
|
|
||||||
// Check if a specific subtype is specified on the element using the 'type' attribute
|
// Check if a specific subtype is specified on the element using the 'type' attribute
|
||||||
string subTypeString = element.GetAttribute(TYPE_ATTR);
|
string subTypeString = element.GetAttribute(TypeAttr);
|
||||||
if (subTypeString != null && subTypeString.Length > 0) {
|
if (subTypeString != null && subTypeString.Length > 0) {
|
||||||
// Read the explicit subtype
|
// Read the explicit subtype
|
||||||
try {
|
try {
|
||||||
@@ -738,7 +773,7 @@ namespace Orchard.Logging {
|
|||||||
// Hack to allow use of Level in property
|
// Hack to allow use of Level in property
|
||||||
if (typeof(Level) == type) {
|
if (typeof(Level) == type) {
|
||||||
// Property wants a level
|
// Property wants a level
|
||||||
Level levelValue = m_hierarchy.LevelMap[value];
|
Level levelValue = _hierarchy.LevelMap[value];
|
||||||
|
|
||||||
if (levelValue == null) {
|
if (levelValue == null) {
|
||||||
LogLog.Error("XmlHierarchyConfigurator: Unknown Level Specified [" + value + "]");
|
LogLog.Error("XmlHierarchyConfigurator: Unknown Level Specified [" + value + "]");
|
||||||
@@ -772,7 +807,7 @@ namespace Orchard.Logging {
|
|||||||
Type objectType = null;
|
Type objectType = null;
|
||||||
|
|
||||||
// Get the object type
|
// Get the object type
|
||||||
string objectTypeString = element.GetAttribute(TYPE_ATTR);
|
string objectTypeString = element.GetAttribute(TypeAttr);
|
||||||
if (objectTypeString == null || objectTypeString.Length == 0) {
|
if (objectTypeString == null || objectTypeString.Length == 0) {
|
||||||
if (defaultTargetType == null) {
|
if (defaultTargetType == null) {
|
||||||
LogLog.Error("XmlHierarchyConfigurator: Object type not specified. Cannot create object of type [" + typeConstraint.FullName + "]. Missing Value or Type.");
|
LogLog.Error("XmlHierarchyConfigurator: Object type not specified. Cannot create object of type [" + typeConstraint.FullName + "]. Missing Value or Type.");
|
||||||
@@ -843,60 +878,5 @@ namespace Orchard.Logging {
|
|||||||
return createdObject;
|
return createdObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Protected Instance Methods
|
|
||||||
|
|
||||||
#region Private Constants
|
|
||||||
|
|
||||||
// String constants used while parsing the XML data
|
|
||||||
private const string CONFIGURATION_TAG = "log4net";
|
|
||||||
private const string RENDERER_TAG = "renderer";
|
|
||||||
private const string APPENDER_TAG = "appender";
|
|
||||||
private const string APPENDER_REF_TAG = "appender-ref";
|
|
||||||
private const string PARAM_TAG = "param";
|
|
||||||
|
|
||||||
// TODO: Deprecate use of category tags
|
|
||||||
private const string CATEGORY_TAG = "category";
|
|
||||||
// TODO: Deprecate use of priority tag
|
|
||||||
private const string PRIORITY_TAG = "priority";
|
|
||||||
|
|
||||||
private const string LOGGER_TAG = "logger";
|
|
||||||
private const string NAME_ATTR = "name";
|
|
||||||
private const string TYPE_ATTR = "type";
|
|
||||||
private const string VALUE_ATTR = "value";
|
|
||||||
private const string ROOT_TAG = "root";
|
|
||||||
private const string LEVEL_TAG = "level";
|
|
||||||
private const string REF_ATTR = "ref";
|
|
||||||
private const string ADDITIVITY_ATTR = "additivity";
|
|
||||||
private const string THRESHOLD_ATTR = "threshold";
|
|
||||||
private const string CONFIG_DEBUG_ATTR = "configDebug";
|
|
||||||
private const string INTERNAL_DEBUG_ATTR = "debug";
|
|
||||||
private const string CONFIG_UPDATE_MODE_ATTR = "update";
|
|
||||||
private const string RENDERING_TYPE_ATTR = "renderingClass";
|
|
||||||
private const string RENDERED_TYPE_ATTR = "renderedClass";
|
|
||||||
|
|
||||||
// flag used on the level element
|
|
||||||
private const string INHERITED = "inherited";
|
|
||||||
|
|
||||||
#endregion Private Constants
|
|
||||||
|
|
||||||
#region Private Instance Fields
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// key: appenderName, value: appender.
|
|
||||||
/// </summary>
|
|
||||||
private Hashtable m_appenderBag;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The Hierarchy being configured.
|
|
||||||
/// </summary>
|
|
||||||
private readonly Hierarchy m_hierarchy;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The snapshot of the environment variables at configuration time, or null if an error has occured during querying them.
|
|
||||||
/// </summary>
|
|
||||||
private IDictionary m_environmentVariables;
|
|
||||||
|
|
||||||
#endregion Private Instance Fields
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user