开发者

Reference to configurated project with log4net

开发者 https://www.devze.com 2023-01-12 22:02 出处:网络
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.

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

精彩评论

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