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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:37:48+00:00 2026-06-02T19:37:48+00:00

class LogUtil<T> : ILogUtility { log4net.ILog log; public LogUtil() { log = log4net.LogManager.GetLogger(typeof(T).FullName); }

  • 0
class LogUtil<T> : ILogUtility
{
    log4net.ILog log;

    public LogUtil()
    {
        log = log4net.LogManager.GetLogger(typeof(T).FullName);
    }

    public void Log(LogType logtype, string message)
    {
        Console.WriteLine("logging coming from class {0} - message {1} " , typeof(T).FullName, message);
    }
}

public class Logger
{
    ILogUtility _logutility;

    public Logger(ILogUtility logutility)
    {
        _logutility = logutility;
    }


    public void Log(LogType logtype, string message)
    {
        _logutility.Log(logtype, message);
    }


}

I need to have the functionality to be flexible and have the ability to remove the LogUtil class in the future and use some thing else.

So I write LoggerUtility wrapper class as follows:

class LoggerUtility<T>
{

    Logger logger;
    public LoggerUtility()
    {
        LogUtil<T> logutil = new LogUtil<T>();

        logger = new Logger(logutil);

    }

    public void Log(LogType logtype, string message)
    {
        logger.Log(logtype, message);
    }

}

My client code as follows:

public class TestCode
{
    public void test()
    {

        new LoggerUtility<TestCode>().Log(LogType.Info, "hello world");

    }

}

To get loose coupling from LogUtil, I end up writing 2 wrapper classes Logger and LoggerUtility. So in the future, if I have to add another method
in the ILogUtility, I would have to add that method to Logger class and then LoggerUtility.

What is the best way to write LoggerUtility so that I could write the client code as follows:

new LoggerUtility<TestCode>().Log(LogType.Info, "hello world");

Please let me know.

Thanks

  • 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-02T19:37:50+00:00Added an answer on June 2, 2026 at 7:37 pm

    It looks like you’re adding a level of abstraction where there really doesn’t need to be one.

    If we start with your end result, LoggerUtility just needs to have an interface that it can use to log things based on the LogType parameter.

    Your Logger class, as its currently written, is just a thin wrapper around the ILogUtility interface. So why bother adding that layer? Why can’t the Logger class use an ILogUtility instance directly? You could even go one step further and define your interface as ILogUtility<T> and know that when you create a LoggerUtility<Foo> that the instance of the logger it will use will be based on the Foo class.

    But honestly, I think you may just be reinventing the wheel here. Take a look at Common Logging for .NET. It will probably ease what you’re trying to do and make more sense in the long run.

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

Sidebar

Related Questions

class LogUtil : ILogUtility { object _classtype; log4net.ILog log; public LogUtil(object classtype) { _classtype
class test <T> where T : class { public void Write<T>() { Console.Write(typeof(T).FullName); }
class ZiggyTest{ public static void main(String[] args){ RunnableThread rt = new RunnableThread(); Thread t1
class ZiggyTest{ public static void main(String[] args) { String str = aaaaaaaaabb; String []
class A { String s4 = abc; static public void main(String[]args ) { String
class foo { public: void say_type_name() { std::cout << typeid(this).name() << std::endl; } };
class Widget { public: Widget() { cout<<~Widget()<<endl; } ~Widget() { cout<<~Widget()<<endl; } void* operator
class Foo(){ public List<string> SomeCollection; } I need to implement an event which can
class B{ private: void DoSomething(); } class W{ private: class D: public B{ }
{ class Program { static void Main(string[] args) { int id = 0, stock

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.