Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8856887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:27:35+00:00 2026-06-14T14:27:35+00:00

I use log4net for my logging needs throughout my solution (which has various projects

  • 0

I use log4net for my logging needs throughout my solution (which has various projects which in return have various classes).

Is it really needed to always create an instance (aka object) like so:

private static readonly ILog log = LogManager.GetLogger(typeof(MyApp));

or the way I do it:

private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

To use log4net? Isn’t there an alternative to this so that I don’t have to do it ever class and thus requires less copy and pasting 🙂 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:27:36+00:00Added an answer on June 14, 2026 at 2:27 pm

    With the help of a tiny helper:

    public static class LogGateway
    {
        static LogGateway() 
        { 
            XmlConfigurator.Configure();  
        }
    
        public static ILog For( object LoggedObject )
        {
            if ( LoggedObject != null )
                return For( LoggedObject.GetType() );
            else
                return For( (string)null );
        }
    
        public static ILog For( Type ObjectType )
        {
            if ( ObjectType != null )
                return LogManager.GetLogger( ObjectType );
            else
                return LogManager.GetLogger( string.Empty );
        }
    
        public static ILog For( string LoggerName )
        {
            return LogManager.GetLogger( LoggerName );
        }
    } 
    

    you don’t duplicate the code, you just refer to the logger as:

    ...
    LogGateway.For( this ).Debug( "hello!" ); // instance method
    LogGateway.For( typeof( Foo ) ).Debug( "hello!" ); // static method
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WCF service where in I use Log4Net for logging information to
I have an ASP.NET MVC app which has a bootstrapper class that configures log4net
I am trying to properly use Ninject to inject log4net logging into my MVC3
We have a ASP .Net application whereby we use Log4Net to log details within
I have a framework that uses log4net for logging, I know that we can
I have a C#.NET 4.0 app that uses log4net for logging. Under Windows XP,
I'm currently investigating various logging possibilities for .net projects and I can't decide between
I have an ASP.NET website and I am doing logging with log4net. As logging
I have php file which contains class FooClass uses in a few projects. I
I have developed a web dashboard which has a structure of controls embedded inside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.