views:

25

answers:

2

Hi,

I have a few applications and I want add to their reference to my class library MyLogger, which bases at log4net. In this library I have App.config file.

So I want configuration file only in this one project/library.

So, this is method in my applications

   public void TestMyLogger()
    {
    MyLogger myLogger=new MyLogger();

    }

and this is MyLogger:

public class MyLogger
    {
        public MyLogger()
        {
            log4net.Config.XmlConfigurator.Configure();

            Log.Fatal("this is a fatal msg");
            Log.Error("this is an error msg");
            Log.Warn("this is a warn msg");
            Log.Info("this is an info msg");
            Log.Debug("this is a debug msg");
}

}

How to correct this, to have everything working?

+1  A: 

I understand your question to mean

I want several applications to reference a logging .dll, which has its own config

hopefully this link is useful :c# dll config file

Given that you can set up a config file for your dll, you should have no problem referencing the same dll in your other projects.

Jonny Cundall
+1  A: 

One tricky point will be to configure Log4net your configuration and not the Application one.

According to Log4net documentation, you will have to configure Log4net using

var myDllConfig = ConfigurationManager.OpenExeConfiguration("foo.dll.config");
XmlConfigurator.Configure(new FileInfo(myDllConfig.FilePath))
la mouette