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

前端 未结 4 1701
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-12 13:35

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 cr

相关标签:
4条回答
  • 2021-02-12 14:19

    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
    */
    
    0 讨论(0)
  • 2021-02-12 14:22

    In response to what Phil Wheeler mentioned above, on a current project I am doing in Mvc4, we have an Mvc area called SiteAdmin. This area will be responsible for all site administration duties, including Elmah.

    To get over the lack of delete functionality, I implemented a function to delete all of the current log entries in Elmah (we're using the XML based version).

    Here is an image of the SiteAdmin index view:

    enter image description here

    • View Error Log - Opens the Elmah UI in a new window.
    • Clear Error Log - Presents a confirmation popup, then deletes all entries if the user confirms.

    If anyone needs the code as an example, I'd be happy to send it along.

    My mechanics could be modified pretty easily to provide a mechanism for selective deletions by criteria if needed (by date, by status code, etc...).

    The point of my answer here is that you could provide the delete functionality on your own AND not fork the open source code of the Elmah project.

    0 讨论(0)
  • 2021-02-12 14:31

    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.

    0 讨论(0)
  • 2021-02-12 14:35

    At least within a MVC project, you can go to the App_Data/Elmah.Errors directory to delete the error XML files that you want to remove.

    0 讨论(0)
提交回复
热议问题