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

前端 未结 4 1711
爱一瞬间的悲伤
爱一瞬间的悲伤 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
    */
    

提交回复
热议问题