Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 
Add your own
alternative version
Go to top

log4net XmlConfigurator Simplified

, 16 Jun 2007
This article covers the configuration of log4net using the XmlConfigurator. This article also demonstrates how to create multiple log files for your application.
MultipleLoggers.zip
MultipleLoggers
bin
Debug
log4net.dll
logs
MyCompany.MultipleLoggers.exe
MyCompany.MultipleLoggers.vshost.exe
MyCompany.MyLibrary1.dll
MyCompany.MyLibrary2.dll
Properties
Settings.settings
MyLibrary1
bin
Debug
MyCompany.MyLibrary1.dll
Properties
MyLibrary2
bin
Debug
MyCompany.MyLibrary2.dll
Properties
log4net_objects.gif
MultipleLoggers.suo
using System;
using System.Collections.Generic;
using System.Text;

using log4net;

namespace MyCompany.MultipleClasses
{
    class Class1
    {
        private log4net.ILog m_Log;
        
        public Class1()
        {
            m_Log = log4net.LogManager.GetLogger(this.GetType().FullName);
        }
        ~Class1()
        {
            m_Log = null;
        }

        public void LogMessages()
        {
            LogMessages(string.Format("Message from {0}", this.GetType().FullName));
        }

        public void LogMessages(string text)
        {
            m_Log.Debug(text);
        }
    }

    class Class2
    {
        private log4net.ILog m_Log;
        
        public Class2()
        {
            m_Log = log4net.LogManager.GetLogger(this.GetType().FullName);
        }
        ~Class2()
        {
            m_Log = null;
        }

        public void LogMessages()
        {
            LogMessages(string.Format("Message from {0}", this.GetType().FullName));
        }

        public void LogMessages(string text)
        {
            m_Log.Debug(text);
        }
    }
    
    class Class3 
    {
        private log4net.ILog m_Log;
        
        public Class3()
        {
            m_Log = log4net.LogManager.GetLogger(this.GetType().FullName);
        }
        ~Class3()
        {
            m_Log = null;
        }

        public void LogMessages()
        {
            LogMessages(string.Format("Message from {0}", this.GetType().FullName));
        }

        public void LogMessages(string text)
        {
            m_Log.Debug(text);
        }
    }

}

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)

Share

About the Author

Joseph Guadagno
Web Developer
United States United States
I have been in software development for about 15 years or so. I started out with a small book on QuickBASIC, then moved the Visual Basic for DOS, then Visual Basic for Windows, then Visual Basic .NET and eventually Visual C#. When I am not working at my full time job I donate my time to several community efforts like:
 
Former President of INETA North America, currently Vice President.
President of the Southeast Valley .NET User Group (SEVDNUG) in Chandler, AZ.
Serving on my City's Parks and Recreation board.
 
I have or have had the following "MVP" awards:
  • Visual Basic MVP in 1996
  • C# MVP since 2009
  • Telerik MVP since 2010
I maintain a Open Source project on CodePlex which wraps the Bing API called BingSharp.
 
I also help / organize or participate in several community events:
  • Desert Code Camp
  • AZGiveCamp
  • Organizer for the 1st Time MVP event at the MVP Summit
  • MVP 2 MVP Sessions at MVP Summit.
  • Awesome bean pusher at GeekGive at the MVP Summit.
Follow on   Twitter

| Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 16 Jun 2007
Article Copyright 2007 by Joseph Guadagno
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid