我知道这个问题this 已经 被 问过 多次 了, 但是很不幸,我一直无法让我的日志配置起作用。我肯定是在某个地方犯了非常小的错误。
"
我有一个.NET 4.5 MVC 4/EF 5的Web应用程序,我正在尝试让日志记录工作。该解决方案有两个项目,一个用于DAO和模型对象,另一个用于网站。 App.Config文件如下:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="RebuildingTogetherEntities" connectionString="stuff..."/>
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
<log4net configSource="Log.config" />
</configuration>
相同的log4net部分也被复制到Web.Config文件中。
我在两个AssemblyInfo.cs文件中添加了以下内容:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log.config", Watch = true)]
"
“Copy To Output Directory”对于两个Log.Config文件都设置为true。
我似乎唯一的方法是在第一条日志记录语句运行之前调用XmlConfigurator.Configure(),才能让日志附加到输出文件中。我猜我可以写一个门面来在我第一次获取记录器时执行这个操作,但那感觉不对。
如何在不手动调用XmlConfigurator的情况下初始化记录器?
"