参考使用log4net配置的项目
我有一些应用程序,我想添加它们对我的类库 MyLogger 的引用,该类库基于 log4net。在这个库中我有 App.config 文件。
所以我只想要这个项目/库中的配置文件。
所以,这是我的应用程序中的方法
public void TestMyLogger()
{
MyLogger myLogger=new MyLogger();
}
,这是 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");
}
}
如何纠正这个问题,让一切正常工作?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个棘手的问题是配置 Log4net 您的配置而不是应用程序配置。
根据 Log4net 文档,您必须使用以下命令配置 Log4net
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
我理解你的问题的意思
希望此链接有用:c# dll config file
鉴于您可以为 dll 设置配置文件,因此在其他项目中引用相同的 dll 应该没有问题。
I understand your question to mean
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.