我正在使用log4net,在我的application_start中我有以下行:
log4net.Config.XmlConfigurator.Configure()
当我构建项目时,我在System.Web.DLL中得到了几百个异常。当我进入它们时,它似乎源于Log4Net,并显示消息“请求在此上下文中不可用”
我在调试器中看到的异常:
An exception of type 'System.Web.HttpException' occurred in System.Web.dll
'Request is not available in this context'
这是我的log4net配置:
<log4net>
<appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
<file value="logs\\" />
<appendToFile value="true" />
<DatePattern value="yyyyMMdd'.log.txt'" />
<rollingStyle value="Date" />
<param name="StaticLogFileName" value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger - %message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="FileAppender" />
<appender-ref ref="aiAppender" />
</root>
<appender name="aiAppender" type="Microsoft.ApplicationInsights.Log4NetAppender.ApplicationInsightsAppender, Microsoft.ApplicationInsights.Log4NetAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message%newline" />
</layout>
</appender>
有关导致所有这些异常的原因的任何想法?我可以忽略它们,事情似乎很好,但只需几分钟就可以调试应用程序。
更新以包含Global.Asax
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
GlobalConfiguration.Configure(Function(config) config.MapHttpAttributeRoutes()
config.Routes.MapHttpRoute(name:="DefaultApi",routeTemplate:="api3/{controller}/{id}", defaults:=New With {Key .id = RouteParameter.[Optional]})
End Function)
AreaRegistration.RegisterAllAreas()
RegisterRoutes(RouteTable.Routes)
log4net.Config.XmlConfigurator.Configure()
End Sub