2013-02-05 85 views
0

我們有一個記錄很多事件的VB.Net 2.0應用程序。.Net/Windows事件日誌:當設置「根據需要覆蓋事件」時,如何保留特定日誌

正如通常的做法,當硬盤空間用完時,爲了停止應用程序失敗,我們設置了「根據需要覆蓋事件」選項。

這意味着我們在任何時候都只有大約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 

有沒有「保留」日誌條目,以便當覆蓋情況也沒有被刪除的方法嗎?

回答

0

當前的解決方法是記錄到輔助日誌:

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