C# log4net独立配置文件
我正在我的项目中使用C# log4net独立配置文件,c#,configuration,log4net,C#,Configuration,Log4net,我正在我的项目中使用log4net。 到目前为止,我使用了App.config文件作为配置文件, 但现在我想把它放在另一个文件中 以下是我所做的: 我搬家了到新文件 (紧跟在之后) 在App.config上,我将代码更改如下: <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </config
log4net
。
到目前为止,我使用了App.config
文件作为配置文件,
但现在我想把它放在另一个文件中
以下是我所做的:
我搬家了代码>到新文件
(
紧跟在
之后)
在App.config
上,我将代码更改如下:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net configSource="log4net.config"/>
但是,此行不会写入Assemblyinfo.cs
。不知道我是否应该
值得一提的是,只要log4net.config
文件位于bin\debug
文件夹中,这项功能就可以正常工作,因此我怀疑是程序集引起了问题,我希望该文件与App.config
文件一起在解决方案中容易看到,而不是在bin
文件夹中。另外,若我在那个里放了一个完整路径为log4net.config
的字符串,那个也可以,但这会给在另一台计算机上使用它带来问题,我怎样才能使它工作呢?谢谢 确保log4net.config文件的属性“Copy to output directory”设置为“Copy if newer”。这样,在运行项目时,它总是复制到bin/debug或bin/release文件夹中
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]