ASP.NET MVC ELMAH错误日志

工具運用得宜可說提高不少效率喔!(好工具帶我們上天堂, 壞工具帶我們住套房XD),

所以今天就來使用elmah替我們紀錄整個網站的例外事件,

該工具設定過程簡單明瞭,重點是'資訊豐富',實在不錯用。

 ELMAH On IIS6

1.download elmah並在專案中加入參考

image

2.編輯Web.config呼叫Elmah

<configuration>

<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>

 

 

<httpHandlers> 

<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />

 

 

 

<httpModules>

<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
 

 

 

 

<system.web>只有有任何列外狀況都將導到Error.aspx

<customErrors mode="On" defaultRedirect="~/Error">
      <error statusCode="404" redirect="~/Error"/>
      <error statusCode="500" redirect="~/Error"/>
</customErrors>
<configuration>導出xml檔案到相關存放路徑
<elmah>
    <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="D:/Log_Data" />   
</elmah>
 

 

 

 

3.Configure routing(RegisterRoutes in Global.asax.cs)

 routes.IgnoreRoute( "elmah.axd" );  
 

 

 

 

到這裡就算完成整個elmah的設定了,現在準備來測試搂。

 

丟出NullException

public ActionResult PersonCreate()
        {
            throw new ArgumentNullException();               
            return View();
        }

 

 

 

image

查看Log(http://server//elmah.axd)

image

點擊Details(擷取部分)

image

xml檔案

image

image

資訊相當詳細完整。

转载于:https://www.cnblogs.com/stalwart/archive/2010/11/18/1880883.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值