我有一个Visual解决方案,包含两个项目:
我的Web应用程序项目没有Log4Net引用。日志项目是一个引用了Log4Net dll的项目,它有一个Manager类,我在其中拥有所有的日志记录方法。
现在,我想知道在网络应用程序WEb.Config文件中我必须做什么,我在互联网上看到我必须添加一个节:
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,
log4net"/>但我担心的是,我的网页项目没有Log4Net dll引用。我有没有办法做到这一点,而不添加Log4Net dll到我的网络项目?
发布于 2014-05-11 02:42:52
是的,您可以在web应用程序项目中添加用于log4net的log4net元素,而无需引用log4net.dll。
当然,我在Visual中使用了针对Visual 4.0的scratch web应用程序项目(WebApplication1)和类库(ClassLibrary1),对此进行了双重检查。ClassLibrary1引用了log4net.dll,但是WebApplication1没有引用;它只是引用了ClassLibrary1,并且在其Web.config:通过log4net登录到文本文件中有一个log4net section元素&相关的log4net元素。
发布于 2014-05-11 09:03:40
您似乎忘记配置log4net了。最佳实践是在assably.cs中添加一个配置属性:
// Configure log4net using the .config file
[assembly: log4net.Config.XmlConfigurator(Watch=true)]
// This will cause log4net to look for a configuration file
// called TestApp.exe.config in the application base
// directory (i.e. the directory containing TestApp.exe)
// The config file will be watched for changes.
// Configure log4net using the .log4net file
[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension="log4net",Watch=true)]
// This will cause log4net to look for a configuration file
// called TestApp.exe.log4net in the application base
// directory (i.e. the directory containing TestApp.ex您可以在log4net dll中添加属性,在您的web项目中不需要引用log4net。
https://stackoverflow.com/questions/23588204
复制相似问题