diff --git a/src/Orchard.Web/Config/log4net.config b/src/Orchard.Web/Config/log4net.config index 3dc7e72bd..999e11599 100644 --- a/src/Orchard.Web/Config/log4net.config +++ b/src/Orchard.Web/Config/log4net.config @@ -54,7 +54,7 @@ - + @@ -73,7 +73,7 @@ - + diff --git a/src/Orchard.Web/Orchard.Web.csproj b/src/Orchard.Web/Orchard.Web.csproj index ec7b050fa..29223a2fb 100644 --- a/src/Orchard.Web/Orchard.Web.csproj +++ b/src/Orchard.Web/Orchard.Web.csproj @@ -195,17 +195,7 @@ - False - False - 30320 - /OrchardLocal - - - False - False - - - False + True diff --git a/src/Orchard/Logging/OrchardLog4netFactory.cs b/src/Orchard/Logging/OrchardLog4netFactory.cs index 5ab8c209d..4a5dd45d4 100644 --- a/src/Orchard/Logging/OrchardLog4netFactory.cs +++ b/src/Orchard/Logging/OrchardLog4netFactory.cs @@ -5,12 +5,8 @@ using System.Web; using System.Web.Hosting; using Castle.Core.Logging; -using Castle.Services.Logging.Log4netIntegration; using log4net; -using log4net.Config; - -using Orchard.Environment.Extensions.Helpers; namespace Orchard.Logging { public class OrchardLog4netFactory : AbstractLoggerFactory { diff --git a/src/Orchard/Logging/OrchardXmlConfigurator.cs b/src/Orchard/Logging/OrchardXmlConfigurator.cs index b301301c5..3d9d77ce2 100644 --- a/src/Orchard/Logging/OrchardXmlConfigurator.cs +++ b/src/Orchard/Logging/OrchardXmlConfigurator.cs @@ -1,20 +1,15 @@ using System; -using System.Xml; -using System.Collections; using System.IO; using System.Reflection; -using System.Threading; -using System.Net; +using System.Xml; using log4net; -using log4net.Appender; -using log4net.Util; using log4net.Repository; using log4net.Repository.Hierarchy; +using log4net.Util; namespace Orchard.Logging { public class OrchardXmlConfigurator { - #region Private Instance Constructors /// /// Private constructor @@ -22,10 +17,6 @@ namespace Orchard.Logging { private OrchardXmlConfigurator() { } - #endregion Protected Instance Constructors - - #region Configure static methods - /// /// Configures log4net using the specified configuration file. /// @@ -76,7 +67,7 @@ namespace Orchard.Logging { /// /// /// - static public void Configure(string configFilename) { + public static void Configure(string configFilename) { Configure(LogManager.GetRepository(Assembly.GetCallingAssembly()), configFilename); } @@ -94,7 +85,7 @@ namespace Orchard.Logging { /// Note that this method will NOT close the stream parameter. /// /// - static public void Configure(Stream configStream) { + public static void Configure(Stream configStream) { Configure(LogManager.GetRepository(Assembly.GetCallingAssembly()), configStream); } @@ -150,7 +141,7 @@ namespace Orchard.Logging { /// /// /// - 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 + "]"); if (String.IsNullOrWhiteSpace(configFilename)) { @@ -214,7 +205,7 @@ namespace Orchard.Logging { /// Note that this method will NOT close the stream parameter. /// /// - 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"); if (configStream == null) { @@ -260,10 +251,6 @@ namespace Orchard.Logging { } } - #endregion Configure static methods - - #region Private Static Methods - /// /// Configures the specified repository using a log4net element. /// @@ -279,7 +266,7 @@ namespace Orchard.Logging { /// to load the configuration from an . /// /// - static private void ConfigureFromXml(ILoggerRepository repository, XmlElement element) { + private static void ConfigureFromXml(ILoggerRepository repository, XmlElement element) { if (element == null) { LogLog.Error("XmlConfigurator: ConfigureFromXml called with null 'element' parameter"); } @@ -319,7 +306,5 @@ namespace Orchard.Logging { } } } - - #endregion Private Static Methods } } diff --git a/src/Orchard/Logging/OrchardXmlHierarchyConfigurator.cs b/src/Orchard/Logging/OrchardXmlHierarchyConfigurator.cs index 156e277e7..0de2b8d63 100644 --- a/src/Orchard/Logging/OrchardXmlHierarchyConfigurator.cs +++ b/src/Orchard/Logging/OrchardXmlHierarchyConfigurator.cs @@ -5,10 +5,10 @@ using System.Reflection; using System.Xml; using log4net.Appender; -using log4net.Util; using log4net.Core; using log4net.ObjectRenderer; using log4net.Repository.Hierarchy; +using log4net.Util; namespace Orchard.Logging { /// @@ -27,7 +27,50 @@ namespace Orchard.Logging { 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"; + + /// + /// key: appenderName, value: appender. + /// + private Hashtable _appenderBag; + + /// + /// The Hierarchy being configured. + /// + private readonly Hierarchy _hierarchy; + + /// + /// The snapshot of the environment variables at configuration time, or null if an error has occured during querying them. + /// + private IDictionary _environmentVariables; /// /// Construct the configurator for a hierarchy @@ -40,14 +83,10 @@ namespace Orchard.Logging { /// /// public OrchardXmlHierarchyConfigurator(Hierarchy hierarchy) { - m_hierarchy = hierarchy; - m_appenderBag = new Hashtable(); + _hierarchy = hierarchy; + _appenderBag = new Hashtable(); } - #endregion Public Instance Constructors - - #region Public Instance Methods - /// /// Configure the hierarchy by parsing a DOM tree of XML elements. /// @@ -58,33 +97,33 @@ namespace Orchard.Logging { /// /// public void Configure(XmlElement element) { - if (element == null || m_hierarchy == null) { + if (element == null || _hierarchy == null) { return; } string rootElementName = element.LocalName; - if (rootElementName != CONFIGURATION_TAG) { - LogLog.Error("XmlHierarchyConfigurator: Xml element is - not a <" + CONFIGURATION_TAG + "> element."); + if (rootElementName != ConfigurationTag) { + LogLog.Error("XmlHierarchyConfigurator: Xml element is - not a <" + ConfigurationTag + "> element."); return; } if (!LogLog.InternalDebugging) { // Look for a debug attribute to enable internal debug - string debugAttribute = element.GetAttribute(INTERNAL_DEBUG_ATTR); - LogLog.Debug("XmlHierarchyConfigurator: " + INTERNAL_DEBUG_ATTR + " attribute [" + debugAttribute + "]."); + string debugAttribute = element.GetAttribute(InternalDebugAttr); + LogLog.Debug("XmlHierarchyConfigurator: " + InternalDebugAttr + " attribute [" + debugAttribute + "]."); if (debugAttribute.Length > 0 && debugAttribute != "null") { LogLog.InternalDebugging = OptionConverter.ToBoolean(debugAttribute, true); } 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") { - LogLog.Warn("XmlHierarchyConfigurator: The \"" + CONFIG_DEBUG_ATTR + "\" attribute is deprecated."); - LogLog.Warn("XmlHierarchyConfigurator: Use the \"" + INTERNAL_DEBUG_ATTR + "\" attribute instead."); + LogLog.Warn("XmlHierarchyConfigurator: The \"" + ConfigDebugAttr + "\" attribute is deprecated."); + LogLog.Warn("XmlHierarchyConfigurator: Use the \"" + InternalDebugAttr + "\" attribute instead."); LogLog.InternalDebugging = OptionConverter.ToBoolean(confDebug, true); } } @@ -93,14 +132,14 @@ namespace Orchard.Logging { ConfigUpdateMode configUpdateMode = ConfigUpdateMode.Merge; // 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) { // Parse the attribute try { configUpdateMode = (ConfigUpdateMode)OptionConverter.ConvertStringTo(typeof(ConfigUpdateMode), configUpdateModeAttribute); } 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 if (configUpdateMode == ConfigUpdateMode.Overwrite) { // Reset to original unset configuration - m_hierarchy.ResetConfiguration(); + _hierarchy.ResetConfiguration(); LogLog.Debug("XmlHierarchyConfigurator: Configuration reset before reading config."); } // Try to retrieve the environment variables try { - m_environmentVariables = System.Environment.GetEnvironmentVariables(); + _environmentVariables = System.Environment.GetEnvironmentVariables(); } catch (System.Security.SecurityException) { - m_environmentVariables = null; + _environmentVariables = null; // This security exception will occur if the caller does not have // unrestricted environment permission. If this occurs the expansion @@ -136,37 +175,37 @@ namespace Orchard.Logging { if (currentNode.NodeType == XmlNodeType.Element) { XmlElement currentElement = (XmlElement)currentNode; - if (currentElement.LocalName == LOGGER_TAG) { + if (currentElement.LocalName == LoggerTag) { ParseLogger(currentElement); } - else if (currentElement.LocalName == CATEGORY_TAG) { + else if (currentElement.LocalName == CategoryTag) { // TODO: deprecated use of category ParseLogger(currentElement); } - else if (currentElement.LocalName == ROOT_TAG) { + else if (currentElement.LocalName == RootTag) { ParseRoot(currentElement); } - else if (currentElement.LocalName == RENDERER_TAG) { + else if (currentElement.LocalName == RendererTag) { ParseRenderer(currentElement); } - else if (currentElement.LocalName == APPENDER_TAG) { + else if (currentElement.LocalName == AppenderTag) { // We ignore appenders in this pass. They will // be found and loaded if they are referenced. } else { // Read the param tags and set properties on the hierarchy - SetParameter(currentElement, m_hierarchy); + SetParameter(currentElement, _hierarchy); } } } // Lastly set the hierarchy threshold - string thresholdStr = element.GetAttribute(THRESHOLD_ATTR); + string thresholdStr = element.GetAttribute(ThresholdAttr); LogLog.Debug("XmlHierarchyConfigurator: Hierarchy Threshold [" + thresholdStr + "]"); if (thresholdStr.Length > 0 && thresholdStr != "null") { Level thresholdLevel = (Level)ConvertStringTo(typeof(Level), thresholdStr); if (thresholdLevel != null) { - m_hierarchy.Threshold = thresholdLevel; + _hierarchy.Threshold = thresholdLevel; } else { 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 } - #endregion Public Instance Methods - - #region Protected Instance Methods - /// /// Parse appenders by IDREF. /// @@ -192,9 +227,9 @@ namespace Orchard.Logging { /// /// 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) { return appender; } @@ -203,7 +238,7 @@ namespace Orchard.Logging { XmlElement element = null; 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) { element = curAppenderElement; break; @@ -218,7 +253,7 @@ namespace Orchard.Logging { else { appender = ParseAppender(element); if (appender != null) { - m_appenderBag[appenderName] = appender; + _appenderBag[appenderName] = appender; } return appender; } @@ -237,8 +272,8 @@ namespace Orchard.Logging { /// /// protected IAppender ParseAppender(XmlElement appenderElement) { - string appenderName = appenderElement.GetAttribute(NAME_ATTR); - string typeName = appenderElement.GetAttribute(TYPE_ATTR); + string appenderName = appenderElement.GetAttribute(NameAttr); + string typeName = appenderElement.GetAttribute(TypeAttr); LogLog.Debug("XmlHierarchyConfigurator: Loading Appender [" + appenderName + "] type: [" + typeName + "]"); try { @@ -251,8 +286,8 @@ namespace Orchard.Logging { XmlElement currentElement = (XmlElement)currentNode; // Look for the appender ref tag - if (currentElement.LocalName == APPENDER_REF_TAG) { - string refName = currentElement.GetAttribute(REF_ATTR); + if (currentElement.LocalName == AppenderRefTag) { + string refName = currentElement.GetAttribute(RefAttr); IAppenderAttachable appenderContainer = appender as IAppenderAttachable; if (appenderContainer != null) { @@ -301,16 +336,16 @@ namespace Orchard.Logging { /// protected void ParseLogger(XmlElement loggerElement) { // Create a new log4net.Logger object from the 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 + "]."); - 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 // to protect potential log operations while logger // configuration is in progress. 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 + "]."); log.Additivity = additivity; @@ -328,7 +363,7 @@ namespace Orchard.Logging { /// /// protected void ParseRoot(XmlElement rootElement) { - Logger root = m_hierarchy.Root; + Logger root = _hierarchy.Root; // logger configuration needs to be atomic lock (root) { ParseChildrenOfLoggerElement(rootElement, root, true); @@ -355,9 +390,9 @@ namespace Orchard.Logging { if (currentNode.NodeType == XmlNodeType.Element) { XmlElement currentElement = (XmlElement)currentNode; - if (currentElement.LocalName == APPENDER_REF_TAG) { + if (currentElement.LocalName == AppenderRefTag) { IAppender appender = FindAppenderByReference(currentElement); - string refName = currentElement.GetAttribute(REF_ATTR); + string refName = currentElement.GetAttribute(RefAttr); if (appender != null) { LogLog.Debug("XmlHierarchyConfigurator: Adding appender named [" + refName + "] to logger [" + log.Name + "]."); log.AddAppender(appender); @@ -366,7 +401,7 @@ namespace Orchard.Logging { 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); } else { @@ -391,8 +426,8 @@ namespace Orchard.Logging { /// /// protected void ParseRenderer(XmlElement element) { - string renderingClassName = element.GetAttribute(RENDERING_TYPE_ATTR); - string renderedClassName = element.GetAttribute(RENDERED_TYPE_ATTR); + string renderingClassName = element.GetAttribute(RenderingTypeAttr); + string renderedClassName = element.GetAttribute(RenderedTypeAttr); LogLog.Debug("XmlHierarchyConfigurator: Rendering class [" + renderingClassName + "], Rendered class [" + renderedClassName + "]."); IObjectRenderer renderer = (IObjectRenderer)OptionConverter.InstantiateByClassName(renderingClassName, typeof(IObjectRenderer), null); @@ -402,7 +437,7 @@ namespace Orchard.Logging { } else { try { - m_hierarchy.RendererMap.Put(SystemInfo.GetTypeFromString(renderedClassName, true, true), renderer); + _hierarchy.RendererMap.Put(SystemInfo.GetTypeFromString(renderedClassName, true, true), renderer); } catch (Exception e) { LogLog.Error("XmlHierarchyConfigurator: Could not find class [" + renderedClassName + "].", e); @@ -427,10 +462,10 @@ namespace Orchard.Logging { loggerName = "root"; } - string levelStr = element.GetAttribute(VALUE_ATTR); + string levelStr = element.GetAttribute(ValueAttr); LogLog.Debug("XmlHierarchyConfigurator: Logger [" + loggerName + "] Level string is [" + levelStr + "]."); - if (INHERITED == levelStr) { + if (Inherited == levelStr) { if (isRoot) { LogLog.Error("XmlHierarchyConfigurator: Root level cannot be inherited. Ignoring directive."); } @@ -468,10 +503,10 @@ namespace Orchard.Logging { /// protected void SetParameter(XmlElement element, object target) { // 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 (element.LocalName != PARAM_TAG || name == null || name.Length == 0) { + if (element.LocalName != ParamTag || name == null || name.Length == 0) { name = element.LocalName; } @@ -505,8 +540,8 @@ namespace Orchard.Logging { else { string propertyValue = null; - if (element.GetAttributeNode(VALUE_ATTR) != null) { - propertyValue = element.GetAttribute(VALUE_ATTR); + if (element.GetAttributeNode(ValueAttr) != null) { + propertyValue = element.GetAttribute(ValueAttr); } else if (element.HasChildNodes) { // Concatenate the CDATA and Text nodes together @@ -523,15 +558,15 @@ namespace Orchard.Logging { } if (propertyValue != null) { - if (m_environmentVariables != null) { + if (_environmentVariables != null) { // Expand environment variables in the string. - propertyValue = OptionConverter.SubstituteVariables(propertyValue, m_environmentVariables); + propertyValue = OptionConverter.SubstituteVariables(propertyValue, _environmentVariables); } Type parsedObjectConversionTargetType = null; // 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) { // Read the explicit subtype try { @@ -738,7 +773,7 @@ namespace Orchard.Logging { // Hack to allow use of Level in property if (typeof(Level) == type) { // Property wants a level - Level levelValue = m_hierarchy.LevelMap[value]; + Level levelValue = _hierarchy.LevelMap[value]; if (levelValue == null) { LogLog.Error("XmlHierarchyConfigurator: Unknown Level Specified [" + value + "]"); @@ -772,7 +807,7 @@ namespace Orchard.Logging { Type objectType = null; // Get the object type - string objectTypeString = element.GetAttribute(TYPE_ATTR); + string objectTypeString = element.GetAttribute(TypeAttr); if (objectTypeString == null || objectTypeString.Length == 0) { if (defaultTargetType == null) { 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; } } - - #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 - - /// - /// key: appenderName, value: appender. - /// - private Hashtable m_appenderBag; - - /// - /// The Hierarchy being configured. - /// - private readonly Hierarchy m_hierarchy; - - /// - /// The snapshot of the environment variables at configuration time, or null if an error has occured during querying them. - /// - private IDictionary m_environmentVariables; - - #endregion Private Instance Fields } }