Using structuremap with log4net wrapper

后端 未结 3 1344
南笙
南笙 2020-12-13 11:34

I have the following interface:

public interface ILogger
{
    void Debug(string message, params object[] values);
    void Info(string message, params objec         


        
3条回答
  •  星月不相逢
    2020-12-13 12:13

    I really need to get out of the habit of answering my own question, but for those who run across it, here's the answer.

    return ObjectFactory.With(type).GetInstance();
    

    I actually have a wrapper to structuremap (to avoid exposing the structuremap dependency to my app) that looks like the following:

    public static class ServiceManager
    {
        public static T Get()
        {
            return ObjectFactory.GetInstance();
        }
    
        public static T Get(Type type)
        {
            return ObjectFactory.With(type).GetInstance();
        }
    }
    

    Any time in the code I need a logger, I call the following:

    ServiceManager.Get(GetType()).Info("Logging page view...");
    

提交回复
热议问题