Vb.net 记录错误和事件,最佳做法?
我目前正在开发一个三层应用程序,现在我开始记录日志,我对最佳实践非常好奇。下面是我的LogEntry接口和模型,然后我在一个名为JsonLogService的服务中实现了它,该服务将这些条目序列化并存储在文件系统中Vb.net 记录错误和事件,最佳做法?,vb.net,logging,3-tier,Vb.net,Logging,3 Tier,我目前正在开发一个三层应用程序,现在我开始记录日志,我对最佳实践非常好奇。下面是我的LogEntry接口和模型,然后我在一个名为JsonLogService的服务中实现了它,该服务将这些条目序列化并存储在文件系统中 Public Interface ILogService Sub Log(logEntry As LogEntry) Sub Log(source As String, type As LogEntryType, message As String) Sub
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
我目前在我的管理器中使用此服务来记录事件发生时的情况,但现在我不确定如何实现此功能以捕获错误
在我的管理器方法中捕获错误是否真的有意义,因为我的测试确实应该防止任何错误发生?在获得错误时使用Try-catch和logerror@Mederic这在经理级别上是可以的,但是在演示层呢?我的表示层(在我看来)不应该直接访问服务,或者该层不应该麻烦,因为错误主要发生在管理器(业务逻辑)层?我不知道你的应用程序是如何构造的,但如果你不能直接使用表示层访问服务。在发生错误时,如何进行数据突发,只向服务发送错误信息,然后将其传递给日志接口?@Mederic该结构通常是三层的。网络、经理、服务。