Click here to Skip to main content
15,896,111 members
Articles / Programming Languages / C#

log4net C# Code Snippets

Rate me:
Please Sign up or sign in to vote.
4.17/5 (4 votes)
25 Mar 2009CPOL7 min read 140.6K   6.3K   84  
Visual Studio Code Snippets to assist with configuration of and logging in log4net
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace TrimWS
{
	partial class FAbout : Form
	{
		#region log4net
		private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
		#endregion //log4net

		#region vars

		#endregion //vars


		#region ctor
		public FAbout()
		{
			if (log.IsDebugEnabled) { log.Debug("Constructing"); }

			InitializeComponent();
			
			string _assemblyVersion = "Unknowen Version";
			try
			{
				_assemblyVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
			}
			catch
			{ }

			_lblVersion.Text = _assemblyVersion;
		}

		#endregion //ctor

		#region public
		#region props


		#endregion //props

		#endregion //public


		#region private

		/// <summary>
		/// This method is for playing with Garbage Collection and is not considered functional code
		/// </summary>
		private void _forceGC()
		{
			if (log.IsInfoEnabled) { log.Info("Forcing Garbage Collection"); }

			if (log.IsInfoEnabled) { log.InfoFormat("Before collection: heap memory {0}", GC.GetTotalMemory(false)); }
			GC.Collect();
			GC.WaitForPendingFinalizers();
			GC.Collect();
			if (log.IsInfoEnabled) { log.InfoFormat("After collection: heap memory {0}", GC.GetTotalMemory(false)); }
		}


		#endregion //private


		#region event handlers
		private void _btnOk_Click(object sender, EventArgs e)
		{
			if (log.IsInfoEnabled) { log.Info("Closing About"); }

			this.Close();
		}

		private void _btnGarbageCollection_Click(object sender, EventArgs e)
		{

		}

		#endregion //event handlers



	}
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
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