ASP.NET健康监测中的问题

发布于 2024-10-16 15:19:12 字数 2606 浏览 3 评论 0原文

我创建了一个继承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

我在 web.config 中配置了这个

<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>

但是我遇到了一个问题。

在此处输入图像描述

我该如何解决这个问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮生面具三千个 2024-10-23 15:19:12

您需要在配置中指定您的类:

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

.NET 正在动态创建该类的实例,因此该类必须是“有效的”。

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".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文