我正在尝试让 Glimpse.Log4Net 在现有的 ASP.Net MVC v4 项目(在 VS2010 中)中工作,遵循此处和此处的文档,但尽管该解决方案编译并运行 Glimpse 并且 log4net 似乎工作正常,但我可以'在我期望的 Glimpse 窗口中看不到 log4net 的内容,如第二个链接中页面末尾附近所示。
我已经使用这种方法对 Autofac 进行了依赖注入,我认为它不会产生干扰,因为我在日志文件中获得了预期的条目。
谁能指出我正确的方向?
在我的控制器中:
public class QuoteController : Controller
{
private readonly PrintCostEntities db;
private readonly ILog logger;
public QuoteController(PrintCostEntities db, ILog logger)
{
if (db == null)
{
throw new ArgumentNullException("db");
}
if (logger == null)
{
throw new ArgumentNullException("logger");
}
this.db = db;
this.logger = logger;
}
public ActionResult Index()
{
this.logger.DebugFormat("Index");
return this.View(this.db.Quotes);
}
}
在 global.asax 中:
public class MvcApplication : System.Web.HttpApplication
{
private readonly ILog logger;
protected MvcApplication()
{
XmlConfigurator.Configure();
this.logger = LogManager.GetLogger(typeof(MvcApplication));
}
protected void Application_Start()
{
this.logger.Debug("Application_Start");
}
}
在 web.config 中:
<configuration>
<configSections>
<section name="glimpse" type="Glimpse.Core.Configuration.Section, Glimpse.Core" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<system.web>
<httpModules>
<add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" />
</httpModules>
<httpHandlers>
<add path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" />
</httpHandlers>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" preCondition="integratedMode" />
</modules>
<handlers>
<add name="Glimpse" path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" preCondition="integratedMode" />
</handlers>
</system.webServer>
<glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd" />
<log4net>
<appender name="GlimpseAppender" type="Glimpse.Log4Net.Appender.GlimpseAppender">
<threshold value="ALL" />
</appender>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<threshold value="ALL" />
<file value="log4net.log" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd" />
<maxSizeRollBackups value="5" />
<param name="StaticLogFileName" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c %m%n" />
</layout>
</appender>
<root>
<appender-ref ref="GlimpseAppender" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>
</configuration>