【问题标题】:.Net / Windows Event Logs: How to keep specific logs when "Overwrite events as needed" is set.Net / Windows 事件日志:设置“根据需要覆盖事件”时如何保留特定日志
【发布时间】:2013-02-05 18:21:15
【问题描述】:

我们有一个记录大量事件的 VB.Net 2.0 应用程序。

按照惯例,为了在 HDD 空间用完时阻止应用程序失败,我们设置了“根据需要覆盖事件”选项。

这意味着我们在任何时候都只有大约 6 小时的日志可供我们使用。

大部分日志仅供参考,可以丢弃,但我们希望保留一些日志以进行故障排除。

由于业务政策,我们无法降低日志记录级别。

示例代码:

Private Shared Sub WriteToEventLog(ByVal message As String,
                                   ByVal type As EventLogEntryType,
                                   ByVal componentName As String)

    Dim eventLog As New EventLog("OurAppEvents")
    eventLog.Source = componentName 
    eventLog.WriteEntry(message, type)
End Sub

有没有办法“保留”一个日志条目,以便在覆盖发生时它不会被删除?

【问题讨论】:

    标签: vb.net event-log


    【解决方案1】:

    当前的解决方法是记录到辅助日志:

    Private Shared Sub WriteToEventLog(ByVal message As String,
                                       ByVal type As EventLogEntryType,
                                       ByVal componentName As String)
    
        Dim eventLog As New EventLog("OurAppEvents")
        eventLog.Source = componentName 
        eventLog.WriteEntry(message, type)
    
        If type = EventLogEntryType.Error Then
    
            Dim errorLog As New EventLog("OurAppErrors")
            errorLog.Source = componentName + "Error"
            errorLog.WriteEntry(message, type)
    
        End If
    
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多