elmah的使用

在C#.Net 网站项目中,经常需要做一些记录错误日志的工作,之前的做法是通常把错误Exception记录到某一张错误日志的数据表中,但做了需要连接VPN的项目之后,对每次查看错误日志,访问数据库的速度真是不能让人满意,遂找了elmah第三方的记录日志的工具来做错误备份,而且elmah 支持很多格式,保存XML或者log记事本文件,以及保存到数据库都支持。我这里只做了保存XML格式在服务器硬盘中,查阅起来也很方便。

1.web.config 配置项目

<?xml version="1.0"?>  
<!--  
    For more information on how to configure your ASP.NET application, please visit  
    http://go.microsoft.com/fwlink/?LinkId=169433  
    -->  
<configuration>  
  <configSections>  
    <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>  
  </configSections>  
  <!--此处配置了记录Log的文件路径-->  
  <elmah>  
    <!--  
            allowRemoteAccess attribute indicates whether remote access is allowed.   
            If this value is set to 0, then the error log web page can only be viewed locally.   
            If this attribute is set to 1 then the error log web page is enabled for both remote and local visitors.  
        -->  
    <security allowRemoteAccess="1"/>  
    <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="D:\Scott\Projects\AZ Sales\06.Construction\SourceCode\AZSales\Log"/>  
  </elmah>  
  
  <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>  
  </system.web>  
  
</configuration>  
配置完毕,网站代码中不需要增加其他任何执行代码。

如何查看elmah日志,直接在Web站点后加入elmah,axd 即可。

如:http://localhost:3721/elmah.axd


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值