blog
twitter
Termite Logging Framework for .NET termite VS Tool online logging
 
tweet tweet tweet tweet tweet

Using the Logging Framework with Visual Basic

Thanks to John Lieurance for this information.

 


 

He’s a quick How To guide in VB / ASP.NET for your logging framework. It’s important to note that while it’s possible to add the BitFactory.Logging.dll to the bin folder of the ASP project, I opted to add it to the “App_Code” folder since that’s what VB programmers are used to.

How to implement The Object Guy’s Logging Framework in ASP.NET using VB code behind.

1)       Create an ASP.NET VB project.

2)       Menu click the root website in Solution Explorer and select Add ASP.NET folder | App_Code.

3)       Copy the BitFactory.Logging.dll and .xml file to the App_Code folder.

4)       Click Website | Add Reference…  and browse to the BitFactory.Logging.dll file under the App_Code folder.

5)       Menu click the root website in Solution Explorer and select Add New Item… Then select Global.

6)       Add the following code to your Global.asax file:

 

Immediately following the Application tag add:

<%@ Import Namespace="BitFactory.Logging" %>

 

Immediately following the Script tag add:

    Private Shared cl As CompositeLogger = New CompositeLogger()

    Public Shared ReadOnly Property myLogger() As CompositeLogger

        Get

            Return cl

        End Get

    End Property

 

    Private Sub InitLogger()

        'create the email logger

        Dim myEmailLogger As Logger = New EmailLogger( _

       (New System.Net.Mail.SmtpClient("smtp.MyHost.com")), _

       "website@MyDomain.com", _

       "webmaster@MyDomain.com")

        myEmailLogger.SeverityThreshold = LogSeverity.Debug

 

        'create the file logger

        Dim myFileLogger As Logger = New FileLogger( _

             Server.MapPath("~\myroot\mylogs\logfile.log"))

        myFileLogger.SeverityThreshold = LogSeverity.Debug

 

        'create a socket logger - wrapped in an insistent logger

        Dim mySocketLogger As Logger = New SerialSocketLogger( _

       "<IP address of my home machine>", _

       12345) 'pick a port number

        mySocketLogger = New InsistentLogger( _

        mySocketLogger, 200, 3600)

        'retain 200 log entries in memory

        'retry a failed socket every hour

        mySocketLogger.SeverityThreshold = LogSeverity.Debug

 

        'add the loggers to the main composite logger

        myLogger.AddLogger("Email", myEmailLogger)

        myLogger.AddLogger("File", myFileLogger)

        myLogger.AddLogger("Socket", mySocketLogger)

       

    End Sub

 

In the Application_Start sub add:

InitLogger()

 

You can now use the myLogger object in the following manner anywhwere within the web application:

ASP.global_asax.myLogger.Log(BitFactory.Logging.LogSeverity.Info, "Hello World :)")