ASP.NET健康监测中的问题
我创建了一个继承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.
How can I solve that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在配置中指定您的类:
.NET 正在动态创建该类的实例,因此该类必须是“有效的”。
You need to specify your class in the configuration:
The .NET is creating instance of the class on the fly, so the class must be "valid".