开发者

Reference to configurated project with log4net

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 MyLo开发者_StackOverflow中文版gger();

    }

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?


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))


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜