【手把手教你Elmah】如何在MVC.NET项目中在线查看【错误日志】
一、 在NuGet下载Elmah.MVC dll文件!
或者点击下载dll文件,并且引用客户端。
二、配置WebConfig
<sectionGroup name="elmah"> <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah"/> <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah"/> <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah"/> <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah"/> </sectionGroup>
<appSettings> <add key="elmah.mvc.disableHandler" value="false"/> <add key="elmah.mvc.disableHandleErrorFilter" value="false"/> <add key="elmah.mvc.requiresAuthentication" value="false"/> <add key="elmah.mvc.IgnoreDefaultRoute" value="false"/> <add key="elmah.mvc.allowedRoles" value="*"/> <add key="elmah.mvc.allowedUsers" value="*"/> <add key="elmah.mvc.route" value="elmah"/> <add key="elmah.mvc.UserAuthCaseSensitive" value="true"/> </appSettings>
<httpHandlers> <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" /> </httpHandlers> <httpModules> <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/> </httpModules>
<modules runAllManagedModulesForAllRequests="true"> <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" /> <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" /> <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" /> </modules>
<elmah> <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data" /> <security allowRemoteAccess="true"/> </elmah>
三、 见证奇迹的时刻
四、 总结Elamh这个组件使用还是比较简单的并且可以在线查看错误日志,不需要写任何C#代码,简单实用!
详情:https://code.google.com/p/elmah/wiki/MVC