Click here to Skip to main content
15,881,882 members
Articles / Programming Languages / C#

An Extension to the Enterprise Library Logging Application Block

Rate me:
Please Sign up or sign in to vote.
4.76/5 (18 votes)
28 Oct 200612 min read 73K   1.5K   51  
Provide more control over logging by extending the Enterprise Library Logging Application Block.
//===============================================================================
// Microsoft patterns & practices Enterprise Library
// Logging Application Block
//===============================================================================
// Copyright � Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================

using System;
using System.Diagnostics;
using System.Windows.Forms;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.Design.Properties;
using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.Design.TraceListeners;
using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.Design.Sources;
using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.Design.Filters;
using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.Design.Formatters;

namespace Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.Design
{
	/// <summary>
	/// Represents the design manager for the exception handling settings configuration section.
	/// </summary>
    public sealed class LoggingConfigurationDesignManager : ConfigurationDesignManager
    {
		/// <summary>
		/// Initialize a new instance of the <see cref="LoggingConfigurationDesignManager"/> class.
		/// </summary>
        public LoggingConfigurationDesignManager()
        {
        }

		/// <summary>
		/// Register the commands and node maps needed for the design manager into the design time.
		/// </summary>
		/// <param name="serviceProvider">The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param>
        public override void Register(IServiceProvider serviceProvider)
        {
			LoggingCommandRegistrar cmdRegistrar = new LoggingCommandRegistrar(serviceProvider);
			cmdRegistrar.Register();
			LoggingNodeMapRegistrar registrar = new LoggingNodeMapRegistrar(serviceProvider);
			registrar.Register();
        }

		/// <summary>
		/// Opens the logging settings configuration section, builds the design time nodes and adds them to the application node.
		/// </summary>
		/// <param name="serviceProvider">The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param>
		/// <param name="rootNode">The root node of the application.</param>
		/// <param name="section">The <see cref="ConfigurationSection"/> that was opened from the <see cref="IConfigurationSource"/>.</param>
        protected override void OpenCore(IServiceProvider serviceProvider, ConfigurationApplicationNode rootNode, ConfigurationSection section)
        {
            if (null != section)
            {
				LoggingSettingsNodeBuilder builder = new LoggingSettingsNodeBuilder(serviceProvider, (LoggingSettings)section);
                rootNode.AddNode(builder.Build());
            }
        }

		/// <summary>
		/// Gets the a <see cref="ConfigurationSectionInfo"/> for the logging settings configuration section.
		/// </summary>
		/// <param name="serviceProvider">The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param>
		/// <returns>A <see cref="ConfigurationSectionInfo"/> for the logging settings configuration section.</returns>
        protected override ConfigurationSectionInfo GetConfigurationSectionInfo(IServiceProvider serviceProvider)
        {
            ConfigurationNode rootNode = ServiceHelper.GetCurrentRootNode(serviceProvider);
            LoggingSettingsNode node = null;
            if (rootNode != null) node = (LoggingSettingsNode)rootNode.Hierarchy.FindNodeByType(rootNode, typeof(LoggingSettingsNode));
            LoggingSettings logggingSection = null;
            if (node != null)
            {
				LoggingSettingsBuilder builder = new LoggingSettingsBuilder(serviceProvider, node);
                logggingSection = builder.Build();
            }
            return new ConfigurationSectionInfo(node, logggingSection, LoggingSettings.SectionName);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions