三分钟集成elmah xml 格式日志到mvc站点

1.通过nuget安装Elmah

ELMAH on XML Log 会自动在web.config 文件中添加配置内容,默认不允许远程访问,日志访问路径是 Elmah.axd,不记录500错误

 

2.修改配置文件

增加500的异常记录,允许远程访问

 <elmah>
    <!--
        See http://code.google.com/p/elmah/wiki/SecuringErrorLogPages for 
        more information on remote access and securing ELMAH.
    -->
    <security allowRemoteAccess="true" />
    <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data/Elmah.Errors" />
    <errorFilter>
      <test>
        <equal binding="HttpStatusCode" value="404" type="Int32" />
        <equal binding="HttpStatusCode" value="500" type="Int32" />
      </test>
    </errorFilter>
  </elmah>

修改访问路径

<location path="log.axd" inheritInChildApplications="false">
    <system.web>
      <httpHandlers>
        <add verb="POST,GET,HEAD" path="log.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
      </httpHandlers>
      <!-- 
        See http://code.google.com/p/elmah/wiki/SecuringErrorLogPages for 
        more information on using ASP.NET authorization securing ELMAH.

      <authorization>
        <allow roles="admin" />
        <deny users="*" />  
      </authorization>
      -->
    </system.web>
    <system.webServer>
      <handlers>
        <add name="ELMAH" verb="POST,GET,HEAD" path="log.axd" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
      </handlers>
    </system.webServer>
  </location>

在nuget上有很多ELMAH的扩展可以存储为其它格式。

 

posted @ 2016-07-06 09:08  Zeroes  阅读(449)  评论(0编辑  收藏  举报