现在 Log4Net.config 没有被加载,因为我将包装类移动到它自己的类项目中
谁能帮忙,我一直在成功使用 log4net,我的 web 项目中基本上有一个静态类(包装器),我从名为 log4net.config 的外部文件加载我的配置,方法是将其添加到 assemblyinfo.cs
// log4net config file
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log4Net.config", Watch = true)]
一切都很好!,现在我决定将我的静态类移至其自己的类项目,以便我可以与其他项目共享我的静态类(包装器)。
log4net.config 仍在 web 项目中,但当然它现在还没有加载,我可以这么说,因为在我的静态类(现在是它自己的项目)中,我正在执行操作,
return LogManager.GetLogger("InfoLogger").IsInfoEnabled;
IsInfoEnabled 返回 false,并且没有记录任何内容,.config文件未被读取...
记住 Log4net 包装器(静态类)位于其自己的类项目中,但 .config 文件位于 ihave 的 Web 项目中..我需要这样,因为 .config 可以逐个项目地更改基础,但通常包装不会。
当然,我想我会创建一个抽象类,然后在我的网络项目中继承,并在需要时覆盖任何内容...但是当然,你不能继承静态类,甚至不能创建抽象类。
我确信其他人已经遇到过这个,有什么想法吗? ..非常感谢任何帮助
Can anyone help, i have been using log4net with success i basically had a static class (wrapper) in my webproject and i load my config from external file called log4net.config by adding this in assemblyinfo.cs
// log4net config file
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log4Net.config", Watch = true)]
All good!, now i decided to move my static class to its own class project so i can share my static class (wrapper) with other projects.
The log4net.config is still in the webproject but of course its not getting loaded now, I can tell this because in my static class (now its own project) i am doing
return LogManager.GetLogger("InfoLogger").IsInfoEnabled;
and IsInfoEnabled returns false, and nothing is being logged, the .config file is not being read...
Remembering the Log4net wrapper (static class) is in its own class project but the .config file is in the web project ihave.. I need it like this because .config can change on a project by project basis but generally the wrapper won't.
Of course i thought i will create an abstract class and just inherit in my webproject and override anything if i need to ... BUT of course you can't inherit static classes or even make abstract..
I am sure someone else has come across this, any ideas? .. any help really appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将 XmlConfigurator 程序集属性放入包装 log4net 的类库中。您可以将 log4net.config 文件保存在 Web 应用程序的根目录中。
第一次初始化 log4net 时会读取 XmlConfigurator 程序集属性。 Log4net 扫描调用程序集以查找属性。
You need to put the XmlConfigurator assembly attribute in the class library that wraps log4net. You can keep your log4net.config file in the root directory of your web application.
The XmlConfigurator assembly attribute is read the first time log4net is initialized. Log4net scans the calling assembly to find the attribute.