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 8592301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:43:16+00:00 2026-06-11T23:43:16+00:00

I am using Autofac as my IoC and from everything I have read on

  • 0

I am using Autofac as my IoC and from everything I have read on topic of DI teaches to use “constructor injection” to explicitly expose class dependencies…
However, I am also using logging facade (Common.Logging) with Log4Net and have created Autofac module to inject it.
Now, in every class in which I want to do some logging I have extra constructor parameter (see sample #1)….

I am wondering if logging DI is necessary when using logging facade?
I understand that explicitly exposing dependencies via constructor signature is a good architecture.
but in case of logging facade I believe following is true:

  • I can still “swap out” logging framework at any time
  • The class IMHO is not really dependent on Logger. If no logging is configured NullLogger is used. It is almost “it’s thre if you need it” vs. “it won’t work unless you supply it” kind of deal…(see sample #2)

So, what do others think? Is injecting logging facade an overkill?
There are some similar questions on this topic but in more general terms (infrastructure) – I am mainly interested in logging….

// IoC "way"
public class MyController : BaseController
{
    private readonly ILog _logger;

    public MyController(ILog logger)
    {
        _logger = logger;
    }

    public IList<Customers> Get()
    {
        _logger.Debug("I am injected via constructor using some IoC!");
    }
}

// just use the logger "way"
public class MyController : BaseController
{
    private static readonly ILog Logger = LogManager.GetCurrentClassLogger();

    public IList<Customers> Get()
    {
        Logger.Debug("Done! I can use it!");
    }
}
  • 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-11T23:43:17+00:00Added an answer on June 11, 2026 at 11:43 pm

    Logging is just infrastructure. Injecting it is overkill. I personally don’t even use an abstraction layer. I use the static classes that the library provides directly. My motivation is that it’s unlikely that I’ll switch logging library in a current project (but might switch for the next project).

    However, you are using controllers in your example. Why do you need to log in them? A controller is just an adapter between the view and the model (business logic). There should be no need to log in it.

    You typically do only log in classes which contains business logic and at the top layer to be able to log unhandled exceptions. Those are the hard cases to debug and therefore the places where logging is required.

    Having to log at other places indicates that you need to refactor to encapsulate your business logic properly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started to use Autofac following this tutorials: http://flexamusements.blogspot.com/2010/09/dependency-injection-part-3-making-our.html Simple class with no
I am using Autofac as my IoC container. I have: IRepository<> , my repository
Using Autofac, I have the following scenario: public class MainClass { public delegate MainClass
I'm using Autofac to handle dependency injection in my application. However, I have one
I am using Autofac to handle dependency injection in my application. In order not
I am using Autofac 2.1.12 to handle my dependency injection, and am having trouble
I'm using Castle DynamicProxy with Autofac. I have an object for which I've created
I'm trying to autowire up my application using Autofac. All is fine apart from
I have run into an issue while creating a data service and using Autofac
I have an MVC3 app using Autofac and a custom membership provider. If I

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.