Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elmah log files deletion, manually or is there a setting?

Tags:

How do I delete the log files that Elmah generates on the server?

Is there a setting within Elmah that I can use to delete log files? I would prefer to specify some criteria (e.g. log files that are older than 30 days).

Or should I write my own code for that ?

like image 595
danielovich Avatar asked Dec 18 '10 18:12

danielovich


People also ask

What is Elmah Axd?

Description. ELMAH (Error Logging Modules and Handlers) is an application-wide error logging facility that is completely pluggable. It can be dynamically added to a running ASP.NET web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment.

How do I view Elmah logs?

Build the application, run it in the browser, and navigate to http://www.yoursite.com/elmah.axd. You are prompted to log in before you see the content. After a successful authentication, you see a web page to remotely view the entire log of recorded exceptions.


2 Answers

You can set the maximum number of log entries, but there isn't a native function for clearing out logs older than a given date. It's a good feature request, though!

If you are storing your error logs in memory the maximum number stored is 500 by default and this requires no additional configuration. Alternatively, you can define the number using the size keyword:

<elmah>     <errorLog type="Elmah.MemoryErrorLog, Elmah" size="50" />   </elmah> 

Setting a fixed size is obviously more important for in-memory or XML-based logging, where resources need to be closely managed. You can define a fixed size for any log type though.

like image 117
Phil.Wheeler Avatar answered Oct 12 '22 10:10

Phil.Wheeler


This SQL script deletes the rows older than the newest "size" rows:

declare @size INTEGER = 50; declare @countno INTEGER; SELECT @countno = count([ErrorId])  FROM [dbo].[ELMAH_Error] /* SELECT TOP (@countno-@size)        [ErrorId]       ,[TimeUtc]       ,[Sequence]   FROM [dbo].[ELMAH_Error]   order by [Sequence] asc GO */ DELETE FROM [dbo].[ELMAH_Error] WHERE [ErrorId] IN (     SELECT t.[ErrorId] FROM (        SELECT TOP (@countno-@size)                [ErrorId]               ,[TimeUtc]               ,[Sequence]           FROM [dbo].[ELMAH_Error]           order by [Sequence] asc       ) t     ) GO   /* -- Print remaining rows SELECT * FROM [dbo].[ELMAH_Error] order by [Sequence] desc */ 
like image 31
RaSor Avatar answered Oct 12 '22 11:10

RaSor