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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:23:12+00:00 2026-05-18T11:23:12+00:00

I wonder if this is something very simple that I’m just missing, or if

  • 0

I wonder if this is something very simple that I’m just missing, or if there’s a lot more to this.

Basically, what I’m trying to do is use StructureMap’s setter injection for a logger implementation. The constructor for the logger that I wish for StructureMap to use accepts a Type parameter for creating the logger:

public class Logger : ILogger
{
    private ILog _log = null;

    public Logger() { _log = LogManager.GetCurrentClassLogger(); }

    public Logger(string name) { _log = LogManager.GetLogger(name); }

    public Logger(Type loggerType) { _log = LogManager.GetLogger(loggerType); }

    // The rest of the implementation...
}

In my bootstrapping code, I initialize it as thus:

ObjectFactory.Configure(x => {
    x.FillAllPropertiesOfType<ILogger>().Use(l =>
        new Logger(l.BuildStack.Current.ConcreteType));
    // Further unrelated bootstrapping...
});

It’s not quite working 100%, and it’s probably just a lack of full understanding on my part. So I have a few questions regarding the behavior I’m seeing:

  1. The “type” that the logger is seeing, when I step through the debugger and drill down into the log4net implementation, is of ILogger. How can I get it to be of the type which contains the setter being injected?
  2. Only setters on StructureMap-built instances are being set. For example, on the repository interfaces/implementations for a data access layer. Other objects, such as my business models, aren’t built from the StructureMap graph and are just instantiated as normal. Is there a way to tell StructureMap to also inject into those? I imagine there isn’t, because how would it know? So then how can I resolve an instance of a properly constructed logger for the type? (I know how to call the resolver, which I do through a service locator, just not how to call it for this specific need.)
  3. It occurs to me that this “just doesn’t feel right.” Maybe I’m missing something about named instances? Because if the bootstrapper manages to graph an implementation of this, how/when then would it supply different instances for each class that has the setter?

Maybe there’s an entirely different/simpler/better way to accomplish what I’m trying to do, and I welcome suggestions for that. Basically, I’m abstracting my logging implementation behind an IoC container, and I need class-specific loggers.

  • 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-05-18T11:23:13+00:00Added an answer on May 18, 2026 at 11:23 am

    Perhaps this is not the exact answer you are looking for, but why not simplify everything by creating an ILoggerFactory? Instead of registering the ILogger, you can register a ILoggerFactory and inject the ILoggerFactory in your classes:

    public interface ILoggerFactory
    {
        ILogger CreateFor(string name);
        ILogger CreateFor<T>();
        ILogger CreateFor(Type loggerType);
    }
    
    public class LoggerFactory : ILoggerFactory
    {
        public ILogger CreateFor(string name)
        {
            return LogManager.GetLogger(name);
        }
    
        public ILogger CreateFor<T>()
        {
            return CreateFor(typeof(T));
        }
    
        public ILogger CreateFor(Type loggerType)
        {
            return LogManager.GetLogger(loggerType);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is a question that when programming I always wonder: What to use when
I know that this is somewhat subjective, but I wonder if there is a
I wonder if someone knows if there is a pre-made solution for this: I
Ok, this is possibly borderline-subjective, but I wonder where one would put a simple
I haven't play enough with this and usually use mocks, but I wonder what
I always wonder why compilers can't figure out simple things that are obvious to
I've been looking for something very simple: How to make a side navigation expand
This is a very simple question. I'm asking because I've never seen it before
I wonder if this would be doable ? To insert an array into one
When I make a query, I often wonder about this: Is it better to

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.