I am re-writing some programs to be of better architecture. They are small, relatively simple multi-project solutions in VS 2017 consisting of a GUI in WinForms, a BLL class library, and a DAL class library - all in VB.NET.
everything is working well, I have few issues. I am using NLog for logging to a DB and it is working well. It is currently only logging on one layer, the GUI. I am throwing all exceptions to the top layer and catching them there, and logging them there.
I want to change how I use NLog and separate it from any of the GUI, BLL, and DAL layers - migrate it to a 4th layer - a utility class library layer.
This is what I have done:
Created a utility class library, with an interface and a public class. The public class inherits NLog Logger and impliments the interface:
Public Interface ILogger
Sub Info(message As String)
Sub Info(ex As Exception, message As String)
Sub Debug(message As String)
Sub Debug(ex As Exception, message As String)
Sub [Error](message As String)
Sub [Error](ex As Exception, message As String)
End Interface
Then, the class:
Imports NLog
Public Class MyLogger
Inherits Logger
Implements ILogger
Public Shared _log As Logger = LogManager.GetLogger("databaseLogger")
Public Sub Debug(message As String) Implements ILogger.Info
_log.Debug(message)
End Sub
Public Sub Debug(ex As Exception, message As String) Implements ILogger.Info
_log.Debug(ex, message)
End Sub
Public Sub Info(message As String) Implements ILogger.Debug
_log.Info(message)
End Sub
Public Sub Info(ex As Exception, message As String) Implements ILogger.Debug
_log.Info(ex, message)
End Sub
Public Sub [Error](message As String) Implements ILogger.Error
_log.Error(message)
End Sub
Public Sub [Error](ex As Exception, message As String) Implements ILogger.Error
_log.Error(ex, message)
End Sub
End Class
I then made a winform project in the same solution, referenced the utility class, and stuck this in the startup form:
Public Class Form1
Private _logger As LogTest2.ILogger
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
_logger.Debug("test")
End Sub
End Class
However, When I run it I am getting am error:
'Object reference not set to an instance of an object.'
I am obviously missing something - I've done quite a bit of searching around SO, and while there are many questions all showing C# examples, I see few VB.NET examples. Can someone help me out?