记录错误和事件,最佳做法?

时间:2017-04-13 07:24:00

标签: vb.net logging 3-tier

我目前正在开发一个3层应用程序,现在我已经开始记录,我对最佳实践感到好奇。下面是我的LogEntry的接口和模型,然后我在一个名为JsonLogService的服务中实现它,它将条目序列化并将它们存储在文件系统中。

Public Interface ILogService

    Sub Log(logEntry As LogEntry)
    Sub Log(source As String, type As LogEntryType, message As String)
    Sub Log(source As String, type As LogEntryType, format As String, ParamArray arguments() As Object)

End Interface

Public Enum LogEntryType
    Information
    Warning
    [Error]
    Debug
End Enum

Public Class LogEntry

    Public Property Source As String
    Public Property Type As LogEntryType
    Public Property Message As String
    Public Property LoggedAt As Date = DateTime.Now

    Public Sub New()

    End Sub

    Public Sub Now(source As String, type As LogEntryType, message As String)
        Me.Source = source
        Me.Type =
        Me.Message = message
    End Sub

    Public Sub New(source As String, type As LogEntryType, format As String, ParamArray arguments() As Object)
        Me.Source = source
        Me.Type = type
        Me.Message = String.Format(format, arguments)
    End Sub

我目前正在我的经理中使用此服务来记录事件发生时的效果,但现在我不确定如何实现此功能以捕获错误。

在我的经理方法中捕获错误是否真的有意义,因为我的测试肯定会阻止在那里发生任何错误?

0 个答案:

没有答案