我已經實現了錯誤處理代碼,以將異常記錄到Splunk(使用log4net),無論它們出現在我的MVC 4應用程序中。問題是,如果在視圖文件(cshtml)中出現異常,則不存在與該異常匹配的Splunk日誌。MVC 4視圖(cshtml)錯誤未通過log4net登錄到Splunk
我通過代碼進行調試,發現所有正確的方法都被調用。當我檢查就是BEING傳遞到ILog.Error(字符串消息)方法的值,該值是:
System.Exception: Test view exception
at ASP._Page_Views_Home_Index_cshtml.Execute() in c:\dev\MyMVCApp\Views\Home\Index.cshtml:line 5
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
at System.Web.WebPages.StartPage.RunPage()
at System.Web.WebPages.StartPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
所有其他日誌的嘗試是,除了從圖異常記錄的消息成功。我的log4net配置如下:
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net, Version=1.2.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a" />
<!-- snip -->
</configSections>
<!-- snip -->
<log4net>
<appender name="SplunkAppender" type="log4net.Appender.RemoteSyslogAppender">
<remoteAddress value="splunk.myawesomeserver.com" />
<remotePort value="2221" />
<layout type="log4net.Layout.PatternLayout">
<ConversionPattern value="[%-5p] (%c) %m%n" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="SplunkAppender" />
</root>
</log4net>
</configuration>
我有這個配置錯了嗎?有一種方法可以在將消息傳遞給ILog.Error()後找出發生了什麼問題?
只想留下一個鏈接到SplunkTCP適配器(我還沒有嘗試過)https://code.google.com/p/splunk-log4net/source/browse/#svn%2Ftrunk%2FSplunk.Log4net – parliament