sql Elmah SQL日志分析

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql Elmah SQL日志分析相关的知识,希望对你有一定的参考价值。

/* Useful for analyzing a Elmah logs stored in a SQL Server */
/* Version 1 */
/* --------------------------------------------------------------*/

DECLARE @StartDateTime datetime
DECLARE @EndDateTime datetime
DECLARE @HourlyThreshold int -- If error count for an hour is greater than this number display in the threshold overflow report

SET @HourlyThreshold = 10
SET @StartDateTime = DATEADD(d, -7, CAST(GETDATE() AS date)) 
SET @EndDateTime = GETDATE()

--- This query will return a total error count for each application within the date boundary
SELECT 
	Application, COUNT(*) TotalErrors 
FROM Elmah_Error 
WHERE TimeUtc > @StartDateTime AND TimeUtc < @EndDateTime
GROUP BY Application
ORDER BY TotalErrors DESC


-- Errors by hour -- summary
SELECT 
	Application, CAST(TimeUtc AS DATE) DateErrorOccured, DATEPART(hh, TimeUtc) ErrorHour, COUNT(*) TotalErrors 
FROM Elmah_Error 
WHERE TimeUtc > @StartDateTime AND TimeUtc < @EndDateTime
GROUP BY Application,CAST(TimeUtc AS DATE), DATEPART(hh, TimeUtc)
ORDER BY TotalErrors DESC


-- Errors by hour but only application that has an avg + threshold will show up on this report
SELECT Application, [Hour], AVG(Totals) AS [Avg]
FROM
(
    SELECT 
	Application, 
      [Hour] = DATEPART(HOUR,    TimeUtc),
      Totals = COUNT(*)
    FROM ELMAH_Error
      WHERE TimeUtc > @StartDateTime AND TimeUtc < @EndDateTime  
    GROUP BY 
		Application, 
		DATEPART(HOUR,    TimeUtc)
  ) AS q
GROUP BY Application, [Hour]
ORDER BY Application

-- Grouped by type and application
-- Errors by hour -- summary
SELECT 
	Application, Type, COUNT(*) TotalErrors 
FROM Elmah_Error 
WHERE TimeUtc > @StartDateTime AND TimeUtc < @EndDateTime
GROUP BY Application, Type
ORDER BY TotalErrors DESC

以上是关于sql Elmah SQL日志分析的主要内容,如果未能解决你的问题,请参考以下文章

ELMAH 日志保留

ELMAH - 没有 HttpContext 的异常日志记录

又一款日志组件:ELMAH日志处理异常

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

通过 Live 应用程序上的 Web 界面查看 ELMAH 日志 [重复]

ELMAH日志组件数据库脚本