Log4Net和GAC-如何引用配置文件? [英] Log4Net and GAC - How to reference Configuration Files?

查看:85
本文介绍了Log4Net和GAC-如何引用配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发过程中,我正在使用log4net,作为项目约束的一部分,我现在需要将其添加到Global Assembly Cache.

I am using log4net during my development, as as part of a project constraint, I now need to add it to the Global Assembly Cache.

日志记录定义位于文件Log4Net.xml中.该文件在我的assemblyinfo中被引用为:[assembly:log4net.Config.XmlConfigurator(ConfigFile ="Log4Net.xml",Watch = true)].只要xml文件与log4net.dll位于同一目录中,一切都可以正常工作.

The logging definitions are in a file Log4Net.xml. That file is referenced in my assemblyinfo as: [assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log4Net.xml", Watch = true)]. So long as the xml file was in the same directory as the log4net.dll, everything has been working fine.

但是,现在我已经将log4net添加到GAC中,它不再能够提取xml文件.

However now that I've added log4net to the GAC, it is no longer picking up the xml file.

有人知道我需要进行哪些更改才能使它再次获取XML文件吗?在组装参考中对补丁进行硬编码是唯一的方法吗?

Does anyone know what I need to change in order to have it pick up the XML file again? Is hardcoding the patch in the assembly reference the only way?

非常感谢

推荐答案

您可以确保将log4net.xml文件设置为始终复制"(右键单击log4net.xml->属性->复制到输出目录=始终复制).为了确保您的配置文件被复制,您应该检查bin \ debug或bin \ release目录,并验证log4net.xml文件是否在应用程序执行的同一目录中.

You might ensure that your log4net.xml file is set to "Copy Always" (Right Click on log4net.xml -> Properties -> Copy to Output Directory = Copy always). To ensure that your config file is being copied, you should check your bin\debug or bin\release directory and verify that the log4net.xml file exists in the same directory that your application executes.

如果这不起作用,则可以尝试在log4net中启用内部调试.要启用内部调试,请将以下密钥添加到您的app.config文件中.这会将内部log4net调试消息发送到Visual Studio输出"窗口(视图"->输出").

If that doesn't workthen you can try enabling internal debugging in log4net. To enable internal debugging, add the following key to your app.config file. This will send internal log4net debug messages to your Visual Studio Output window (View -> Output).

<configuration>
  <appSettings>
    <add key="log4net.Internal.Debug" value="true"/>
  </appSettings>
</configuration>

有关log4net内部调试的更多信息,您可以查看Phil Haack的博客文章这里.

For more information on log4net's internal debugging, you might check Phil Haack's blog post here.

如果其他所有方法均失败,则可以通过调用log4net的XmlConfigurator.ConfigureAndWatch方法来打开内部调试并显式加载配置.

If all else fails, you can turn on internal debugging and explicitly load the configuration by calling log4net's XmlConfigurator.ConfigureAndWatch method.

var fi = new FileInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\log4net.xml");
XmlConfigurator.ConfigureAndWatch(fi);

这篇关于Log4Net和GAC-如何引用配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆