现在Log4Net.config没有被加载,因为我感动我的包装类,以自己的类项目我的、自己的、加载、现在

2023-09-07 01:10:04 作者:挚爱め

谁能帮助,我一直在使用log4net的已经有成功,我基本上都在我的webproject有一个静态类(包装),我在AssemblyInfo.cs中添加此加载外部文件调用log4net.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.

该log4net.config在webproject仍在,但当然它没有得到加载,现在,我可以说,是因为在我的静态类(现为自己的项目),我在做

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;

和IsInfoEnabled返回false,并正在记录什么的config文件没有被读取...

and IsInfoEnabled returns false, and nothing is being logged, the .config file is not being read...

记住log4net的包装(静态类)是在其自己的类项目,但config文件是在web项目IHAVE ..我需要它这样的,因为.config文件可以通过项目的基础,但一般在包装上的一个项目更改不会的。

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.

当然,我想我会创建一个抽象类,只是继承我的webproject并覆盖任何东西,如果我需要...但你当然不能继承静态类,甚至使抽象的。

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

我肯定有其他人遇到这一点,任何想法? ..任何帮助真的AP preciated

I am sure someone else has come across this, any ideas? .. any help really appreciated

推荐答案

您需要把XmlConfigurator集属性的类库,它包装log4net的。你可以保持您的log4net.config文件在你的web应用程序的根目录下。

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.

在XmlConfigurator组件属性读取首次log4net的初始化。 log4net的扫描调用程序集找到的属性。

The XmlConfigurator assembly attribute is read the first time log4net is initialized. Log4net scans the calling assembly to find the attribute.