http://www.cnblogs.com/apsnet/archive/2012/04/28/2474730.html

 1. Elmah使用后,在发布时,要区分IIS6和IIS7 ,IIS6下 HttpModules必须在web.config或App.config 配置文件中使用 system.web注册,而IIS7 必须使用 sysem.webserver.

IIS6:

1   <system.web>
2 <httpModules>
3 <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
4 </httpModules>
5 </system.web>

IIS7:

1   <system.webServer>
2 <modules>
3 <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
4 </modules>
5 </system.webServer>
令外介绍下Elmah使用,这个是一款ASP.NET下的系统错误记录管理工具。
下载相应的dll,引用到project.
如果想记录在数据库,必须建立一张错误记录表。web.config配置如下.
 1 <configSections>
2 <sectionGroup name="elmah">
3 <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah"/>
4 <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah"/>
5 <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah"/>
6 <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah"/>
7 </sectionGroup>
8 </configSections>
9
10 <connectionStrings>
11 <add name="strCon" connectionString="Data Source=J18423X;Initial Catalog=UserDB;User ID=sa;Password=1234" providerName="System.Data.SqlClient"/>
12 </connectionStrings>
13
14 <elmah>
15 <security allowRemoteAccess="0" />
16 <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="strCon" />
17 </elmah>
18
19 <httpHandlers>
20 <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah"/>
21 </httpHandlers>
22
//注意httpModules在IIS6和7中需要注意,如问题所述。
23 <httpModules>
24 <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
25 </httpModules>
26
27 <location path="elmah.axd">
28 <system.web>
29 <authorization>
30 <deny users="?"/>
31 </authorization>
32 </system.web>
33 </location>

数据库相关

/* 错误管理工具 SQL代码             */
CREATE TABLE dbo.ELMAH_Error
(
ErrorId UNIQUEIDENTIFIER NOT NULL,
Application NVARCHAR(60) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
Host NVARCHAR(50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
Type NVARCHAR(100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
Source NVARCHAR(60) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
Message NVARCHAR(500) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[User] NVARCHAR(50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
StatusCode INT NOT NULL,
TimeUtc DATETIME NOT NULL,
Sequence INT IDENTITY (1, 1) NOT NULL,
AllXml NTEXT COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

//创建主键

ALTER TABLE dbo.ELMAH_Error WITH NOCHECK ADD
CONSTRAINT PK_ELMAH_Error PRIMARY KEY NONCLUSTERED
(
ErrorId
) ON [PRIMARY]
GO

//创建默认约束

ALTER TABLE dbo.ELMAH_Error ADD
CONSTRAINT DF_ELMAH_Error_ErrorId DEFAULT (newid()) FOR [ErrorId]
GO

//创建非聚集索引

CREATE NONCLUSTERED INDEX IX_ELMAH_Error_App_Time_Seq ON dbo.ELMAH_Error
(
[Application] ASC,
[TimeUtc] DESC,
[Sequence] DESC
) ON [PRIMARY]
GO

SET QUOTED_IDENTIFIER ON

GO

SET ANSI_NULLS ON

GO

//创建存储过程,得到单个错误xml

CREATE PROCEDURE dbo.ELMAH_GetErrorXml
(
@Application NVARCHAR(60),
@ErrorId UNIQUEIDENTIFIER
)
AS
SET NOCOUNT ON
SELECT
AllXml
FROM
ELMAH_Error
WHERE
ErrorId = @ErrorId
AND
Application = @Application
GO SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

//创建存储过程,得到错误总记录

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE dbo.ELMAH_GetErrorsXml
(
@Application NVARCHAR(60),
@PageIndex INT = 0,
@PageSize INT = 15,
@TotalCount INT OUTPUT
)
AS
SET NOCOUNT ON
DECLARE @FirstTimeUTC DateTime
DECLARE @FirstSequence int
DECLARE @StartRow int
DECLARE @StartRowIndex int
-- Get the ID of the first error for the requested page
SET @StartRowIndex = @PageIndex * @PageSize + 1
SET ROWCOUNT @StartRowIndex
SELECT
@FirstTimeUTC = TimeUTC,
@FirstSequence = Sequence
FROM
ELMAH_Error
WHERE
Application = @Application
ORDER BY
TimeUTC DESC,
Sequence DESC
-- Now set the row count to the requested page size and get
-- all records below it for the pertaining application.
SET ROWCOUNT @PageSize
SELECT
@TotalCount = COUNT(1)
FROM
ELMAH_Error
WHERE
Application = @Application
SELECT
errorId,
application,
host,
type,
source,
message,
[user],
statusCode,
CONVERT(VARCHAR(50), TimeUtc, 126) + 'Z' time
FROM
ELMAH_Error error
WHERE
Application = @Application
AND
TimeUTC <= @FirstTimeUTC
AND
Sequence <= @FirstSequence
ORDER BY
TimeUTC DESC,
Sequence DESC
FOR
XML AUTO
GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO

//存储过程:插入数据

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE dbo.ELMAH_LogError
(
@ErrorId UNIQUEIDENTIFIER,
@Application NVARCHAR(60),
@Host NVARCHAR(30),
@Type NVARCHAR(100),
@Source NVARCHAR(60),
@Message NVARCHAR(500),
@User NVARCHAR(50),
@AllXml NTEXT,
@StatusCode INT,
@TimeUtc DATETIME
)
AS
SET NOCOUNT ON
INSERT
INTO
ELMAH_Error
(
ErrorId,
Application,
Host,
Type,
Source,
Message,
[User],
AllXml,
StatusCode,
TimeUtc
)
VALUES
(
@ErrorId,
@Application,
@Host,
@Type,
@Source,
@Message,
@User,
@AllXml,
@StatusCode,
@TimeUtc
)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

使用 Elmah一些要注意的问题的更多相关文章

  1. C#组件系列———又一款日志组件:Elmah的学习和分享

    前言:好久没动笔了,都有点生疏,12月都要接近尾声,可是这月连一篇的产出都没有,不能坏了“规矩”,今天还是来写一篇.最近个把月确实很忙,不过每天早上还是会抽空来园子里逛逛.一如既往,园子里每年这个时候 ...

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

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

  3. ElasticSearch+NLog+Elmah实现Asp.Net分布式日志管理

    本文将介绍使用NLOG.Elmah结合ElasticSearch实现分布式日志管理. 一.ElasticSearch简介 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布 ...

  4. Elmah 日志记录组件

    http://www.cnblogs.com/jys509/p/4571298.html 简介 ELMAH(Error Logging Modules and Handlers)错误日志记录模块和处理 ...

  5. ELMAH入门

    简介 ELMAH(Error Logging Modules and Handlers)错误日志记录模块和处理程序,是一种应用广泛的错误日志工具是完全可插拔.它可以动态添加到一个正在运行的ASP.NE ...

  6. 【工具推荐】ELMAH——可插拔错误日志工具

    今天看到一篇文章(构建ASP.NET网站十大必备工具(2)),里面介绍了一个ELMAH的错误日志工具,于是研究了一下. ELMAH 是 Error Logging Modules and Handle ...

  7. Using sql azure for Elmah

    The MSDN docs contain the list of T-SQL that is either partially supported or not supported.  For ex ...

  8. 【手把手教你Elmah】如何在MVC.NET项目中在线查看【错误日志】

     一.  在NuGet下载Elmah.MVC dll文件!  或者点击下载dll文件,并且引用客户端. 二.配置WebConfig <sectionGroup name="elmah& ...

  9. ELMAH+MVC4+SQLite 错误日志

    任何程序我想无论是在调试开发阶段还是上线运营阶段,都能够使人“放心”,不要出什么意外,也不要玩什么心跳:那就需要比较到位和及时的异常与错误日志模块. 本文将简要描述ELMAH.MVC4与SQLite这 ...

随机推荐

  1. 一起学HTML基础-CSS样式表-基本概念、分类、选择器

    一.基本概念: CSS  (Cascading Style Sheets)层叠样式表,是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言. ...

  2. dede使用方法----如何去掉dede自带的版权

    最近有朋友问如何将dede的Power by DedeCms去掉,一来为了安全,二来外链确实有些影响,这里分享下去除方法,需要的朋友可以参考下   自从dedecms织梦系统更新到6.7日的版本,底部 ...

  3. NPOI导出模板样式

    /// <summary> /// 导出多种车辆统计表格 /// </summary> /// <returns></returns> [ActionN ...

  4. GridView多表关联

    有些时候,需要多表关联查询,使用SqlDataProvider比较灵活 Controller中 use yii\data\SqlDataProvider; $dataProvider = new Sq ...

  5. How to fix the sources list

    How to fix the sources list Sometimes the apt-get may not work, it is often caused by the misspelled ...

  6. 【poj3342】 Party at Hali-Bula

    http://poj.org/problem?id=3342 (题目链接) 题意 给出一棵树,要求在不存在两个节点相邻的条件下,选出尽可能多的节点,并且判断是否有多种选法. Solution 很水的树 ...

  7. Scala类基础

    最近在开始学习Scala,本篇文章我们来讲解一下Scala中类的使用 class Counter { var defaultValue = 0 val valValue = 0 private var ...

  8. UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-13: ordinal not i│ n range(128)

    python保持网页文件遇到的错误,归根结底还是编码问题,改一下要保存的数据为utf-8就好了. 如下最简单: import sys reload(sys) sys.setdefaultencodin ...

  9. oracle创建用户、表空间、授权

    1.打开sqlplus 2.建表空间.用户.授权

  10. hdu 2031 杨辉三角

    题意:显示杨辉三角形. 解法: 组合数学公式:combi(n,m)=combi(n-1,m-1)+combi(n-1,m); 至于为什么有这个公式呢?那就是高中数学的内容啦 1: #include&l ...