0

I created a File Cleanup Provider that is inherits system.web.management.webeventprovider.

Public Class FileCleanupProvider
    Inherits System.Web.Management.WebEventProvider

    Private Const StateFIleFolderPath As String = "StateData/"


    Public Overrides Sub Initialize(ByVal name As String, ByVal config As System.Collections.Specialized.NameValueCollection)
        MyBase.Initialize(name, config)
    End Sub


    Public Overrides Sub Flush()
        ' not required
    End Sub


    Public Overrides Sub ProcessEvent(ByVal raisedEvent As System.Web.Management.WebBaseEvent)

        Dim DateTimeRaised As DateTime = raisedEvent.EventTime
        ' Remove files
        Dim FilePath As String = IO.Path.Combine(HttpRuntime.AppDomainAppPath, StateFIleFolderPath)
        For Each FileName In IO.Directory.GetFiles(FilePath)
            If (DateTimeRaised - IO.File.GetCreationTime(FileName)) > TimeSpan.FromHours(6) Then
                IO.File.Delete(FileName)
            End If
        Next

    End Sub


    Public Overrides Sub ShutDown()
        'Clean up on shut down
        Dim FilePath As String = IO.Path.Combine(HttpRuntime.AppDomainAppPath, StateFIleFolderPath)
        For Each FileName In IO.Directory.GetFiles(FilePath)
            IO.File.Delete(FileName)
        Next
    End Sub

End Class

And I configure in web.config this

<healthMonitoring enabled="true" heartbeatInterval="5">
      <providers>
        <add name="FileCleanupProvider" type="System.Web.Management.WebEventProvider"/>
      </providers>
      <profiles>
        <remove name="Default"/>
        <add name="Default" minInstances="1" maxLimit="Infinite" minInterval="00:01:00" custom=""/>
      </profiles>
      <eventMappings>
        <remove name="Heartbeats"/>
        <add name="Heartbeats" type="System.Web.Management.WebHeartbeatEvent,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" startEventCode="0" endEventCode="2147483647" />
      </eventMappings>
      <!--<eventMappings>
        <add name="FileCleanupEvent" type="System.Web.Management.WebHeartbeatEvent" startEventCode="0" endEventCode="2147483647"/>
      </eventMappings>-->
      <rules>
        <clear/>
        <add name="FileCleanupRule" eventName="Heartbeats" provider="FileCleanupProvider" profile="Default"/>
      </rules>
    </healthMonitoring>

But I got one problem that.

enter image description here

How can I solve that?

4

1 回答 1

1

You need to specify your class in the configuration:

<add name="FileCleanupProvider" type="YourNameSpace.FileCleanupProvider,AssemblyName,Version=0.0.0.0,Culture=neutral,PublicKeyToken=PublicKeyHere"/>

The .NET is creating instance of the class on the fly, so the class must be "valid".

于 2011-02-10T08:20:31.470 回答