Represents the configuration section for the logging aspect
See also base object System.Configuration.ConfigurationSection http://www.codeproject.com/Articles/32490/Custom-Configuration-Sections-for-Lazy-Coders
Inheritance: System.Configuration.ConfigurationSection
Beispiel #1
0
        /// <summary>
        /// Get this configuration set from a specific config file
        /// </summary>
        /// <param name="path"> The path. </param>
        /// <returns> The <see cref="LogAspectConfig"/>. </returns>
        public static LogAspectConfig Open(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            if (instance == null)
            {
                originalConfigPath = path.EndsWith(".config", StringComparison.OrdinalIgnoreCase)
                                         ? path.Remove(path.Length - 7)
                                         : path;

                Configuration config = ConfigurationManager.OpenExeConfiguration(originalConfigPath);

                if (config.Sections[LogAspectSectionName] == null)
                {
                    instance = new LogAspectConfig();
                    config.Sections.Add(LogAspectSectionName, instance);
                    config.Save(ConfigurationSaveMode.Modified);
                }
                else
                {
                    instance = (LogAspectConfig)config.Sections[LogAspectSectionName];
                }
            }

            return(instance);
        }
Beispiel #2
0
        /// <summary>
        /// Save the current property values to the config file
        /// </summary>
        // ReSharper disable once UnusedMember.Global
        public void Save()
        {
            Configuration   config  = ConfigurationManager.OpenExeConfiguration(originalConfigPath);
            LogAspectConfig section = Open(originalConfigPath);

            section.UseConsoleLogger = UseConsoleLogger;
            section.Logger           = Logger;

            config.Save(ConfigurationSaveMode.Full);
        }
Beispiel #3
0
        /// <summary>
        /// The copy.
        /// </summary>
        /// <returns> The <see cref="LogAspectConfig"/>. </returns>
        // ReSharper disable once UnusedMember.Global
        public LogAspectConfig Copy()
        {
            LogAspectConfig copy = new LogAspectConfig();
            string          xml  = SerializeSection(this, LogAspectSectionName, ConfigurationSaveMode.Full);

            using (StringReader stringReader = new StringReader(xml))
            {
                XmlReader reader = new XmlTextReader(stringReader);
                copy.DeserializeSection(reader);
                return(copy);
            }
        }
Beispiel #4
0
 /// <summary>
 /// The copy.
 /// </summary>
 /// <returns> The <see cref="LogAspectConfig"/>. </returns>
 // ReSharper disable once UnusedMember.Global
 public LogAspectConfig Copy()
 {
     LogAspectConfig copy = new LogAspectConfig();
     string xml = SerializeSection(this, LogAspectSectionName, ConfigurationSaveMode.Full);
     using (StringReader stringReader = new StringReader(xml))
     {
         XmlReader reader = new XmlTextReader(stringReader);
         copy.DeserializeSection(reader);
         return copy;
     }
 }
Beispiel #5
0
        /// <summary>
        /// Get this configuration set from a specific config file
        /// </summary>
        /// <param name="path"> The path. </param>
        /// <returns> The <see cref="LogAspectConfig"/>. </returns>
        public static LogAspectConfig Open(string path)
        {
            if (path == null) throw new ArgumentNullException("path");

            if (instance == null)
            {
                originalConfigPath = path.EndsWith(".config", StringComparison.OrdinalIgnoreCase)
                                         ? path.Remove(path.Length - 7)
                                         : path;

                Configuration config = ConfigurationManager.OpenExeConfiguration(originalConfigPath);

                if (config.Sections[LogAspectSectionName] == null)
                {
                    instance = new LogAspectConfig();
                    config.Sections.Add(LogAspectSectionName, instance);
                    config.Save(ConfigurationSaveMode.Modified);
                }
                else
                {
                    instance = (LogAspectConfig)config.Sections[LogAspectSectionName];
                }
            }

            return instance;
        }