The ILogger
interface merely stipulates that a logger has a name andmin level property, and a Log
method accepting a LogLevel
and a message
the formatted log output:
Option Explicit
Option Explicit
Public Sub Log(ByVal output As String)
End Sub
Public Property Get loggerNameName() As String
End Property
Public Property Get MinLevel() As LogLevel
End Property
The client code could implement ILogger
differently, and make one that writes TRACE
, DEBUG
and INFO
log entries to the immediate paneinto, say, a database. WARNFileLogger
and ERROR
entries to a file, and FATAL
entries could cause an email to be sent via Outlook: it's just an interface, the implementation does the real work, DebugLogger
and FileLogger
just so happen to be useful enoughare provided for most usagesconvenience, so the client code most often doesn't need to implement thebut nothing forbids implementing and registering custom ILogger
interfaces on the client side.
2014年09月28日 19:2242:3344 TestLogger [ERROR] Division by zero
The ILogger
interface merely stipulates that a logger has a name and a Log
method accepting a LogLevel
and a message
:
Option Explicit
Public Sub Log(ByVal output As String)
End Sub
Public Property Get loggerName() As String
End Property
The client code could implement ILogger
differently, and make one that writes TRACE
, DEBUG
and INFO
entries to the immediate pane, WARN
and ERROR
entries to a file, and FATAL
entries could cause an email to be sent via Outlook: it's just an interface, the implementation does the real work, DebugLogger
and FileLogger
just so happen to be useful enough for most usages, so the client code most often doesn't need to implement the ILogger
interface.
2014年09月28日 19:22:33 TestLogger [ERROR] Division by zero
The ILogger
interface merely stipulates that a logger has a name andmin level property, and a Log
method accepting the formatted log output:
Option Explicit
Public Sub Log(ByVal output As String)
End Sub
Public Property Get Name() As String
End Property
Public Property Get MinLevel() As LogLevel
End Property
The client code could implement ILogger
differently, and make one that writes log entries into, say, a database. FileLogger
and DebugLogger
are provided for convenience, but nothing forbids implementing and registering custom ILogger
s on the client side.
2014年09月28日 19:42:44 TestLogger [ERROR] Division by zero