ELMAH (ASP.NET錯誤日誌處理)使用方法
阿新 • • 發佈:2019-02-09
ELMAH(Error Logging Modules and Handlers for ASP.NET )是一款ASP.NET下的系統錯誤記錄管理工具,它可以非常方便的把“黃屏”錯誤記錄到XML,MS SQLServer,SQLite,MySql等檔案中,甚至它還可以傳送郵件。
這裡我就記一下使用它的方法。本文以記錄到MS SQL Server 2005為例:
1. 下載ELMAH
2.把dll檔案複製到專案的bin目錄下。
DLL檔案:Elmah.dll
版本:1.0.9414.1441
大小:114688 bytes ( 112.000 KB, 0.109 MB )
3.設定Web.config
?>
<configuration>
<configSections>
<錯誤日誌管理系統 />
<sectionGroup>
<configSections>
<elmah/>
<elmah>
< elmah只允許管理員訪問>
<system.web>
<authorization/>
<authorization>
<system.web>
<location
< 連線字串> <connectionStrings> <add name="ConnectionString" connectionString="Data Source=qq\SQLEXPRESS;Initial Catalog=xx;User ID=xx;Password=xx" providerName="System.Data.SqlClient" /> <connectionStrings> <system.web> <httpHandlers> <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/> <httpHandlers> <httpModules> <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/> <httpModules> <compilation debug="true" /> <authentication mode="Forms"> <forms loginUrl="login.aspx" name=".ASPXAUTH"><forms> <authentication> <authorization> <deny users="*"/> <authorization> <system.web> <configuration>
4.向資料新增表
/* 錯誤管理工具 SQL程式碼 */ GO
5 預覽
可能需要先登入login.aspx.如果不需要登入,可以在web.config裡刪掉相應程式碼.