Click here to Skip to main content
15,885,782 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.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using EntLibLoggingExtended;

namespace EntLibLoggingExQuickStart
{
    public partial class FilterQueryForm : Form
    {
        private ICollection<Category> categories = new List<Category>(0);
        private Priority priority = Priority.None;

        /// <summary>
        /// Priority to use in priority filter query.
        /// </summary>
        public Priority Priority
        {
            get { return this.priority; }
        }

        /// <summary>
        /// Collection of categories to use for category filter query.
        /// </summary>
        public ICollection<Category> Categories
        {
            get { return categories; }
        }

        public FilterQueryForm()
        {
            InitializeComponent();
        }

        private void OkButton_Click(object sender, EventArgs e)
        {
            RecordSelectedCategories();
            RecordSelectedPriority();

            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void CancelEntryButton_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void RecordSelectedPriority()
        {
            if (this.priorityCriticalRadioButton.Checked)
            {
                priority = Priority.Critical;
            }
            else if (this.priorityDebugRadioButton.Checked)
            {
                priority = Priority.Debug;
            }
            else if (this.priorityHighRadioButton.Checked)
            {
                priority = Priority.High;
            }
            else if (this.priorityLowRadioButton.Checked)
            {
                priority = Priority.Low;
            }
            else if (this.priorityMediumRadioButton.Checked)
            {
                priority = Priority.Medium;
            }
            else if (this.priorityTraceRadioButton.Checked)
            {
                priority = Priority.Trace;
            }
        }

        private void RecordSelectedCategories()
        {
            categories.Clear();

            if (this.categoryAssertCheckbox.Checked)
            {
                categories.Add(Category.Assert);
            }
            if (this.categoryBusinessCheckbox.Checked)
            {
                categories.Add(Category.Business);
            }
            if (this.categoryDataAccessCheckbox.Checked)
            {
                categories.Add(Category.DataAccess);
            }
            if (this.categoryDebugCheckbox.Checked)
            {
                categories.Add(Category.Debug);
            }
            if (this.categoryGeneralCheckbox.Checked)
            {
                categories.Add(Category.General);
            }
            if (this.categorySecurityCheckbox.Checked)
            {
                categories.Add(Category.Security);
            }
            if (this.categoryServiceCheckbox.Checked)
            {
                categories.Add(Category.Service);
            }
            if (this.categoryTraceCheckBox.Checked)
            {
                categories.Add(Category.Trace);
            }
            if (this.categoryUiCheckbox.Checked)
            {
                categories.Add(Category.UI);
            }
        }
    }
}

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