'****************************************************** ' * ' * Name: clsAppLogging ' * ' * Design Phase: ' * Author: John Miner ' * Date: 07/01/2008 ' * Purpose: Logging to file and event logs. ' * ' ****************************************************** ' ' Class Usage ' ' 1.0 Must set local file name first ' 2.0 Call Log Message() ' 3.0 If not sucess or information, log to app event log ' 4.0 Log to local txt file with date time stamp ' ' Define all variables Option Explicit ' Define event log constants Const Event_Success = 0 Const Event_Error = 1 Const Event_Warning = 2 Const Event_Information = 4 ' Define file constants const File_Write = 2 const File_Append = 8 ' ' Define the class ' Class clsAppLogging ' -- Data element 1 -- Private strFileName Public Property Get FileName FileName = strFileName End Property Public Property Let FileName(varFileName) strFileName = varFileName End Property ' -- Data element 2 -- Private strAppName Public Property Get AppName AppName = strAppName End Property Public Property Let AppName(varAppName) strAppName = varAppName End Property ' -- Data element 3 -- Private strMsg Public Property Get Message Message = strMsg End Property Public Property Let Message(varMsg) strMsg = varMsg End Property ' -- Data element 4 -- Private intEvent Public Property Get Events Events = intEvent End Property Public Property Let Events(varEvent) intEvent = varEvent End Property ' ' Interface for file & event logging ' Public Sub Write() ' Write to system event log If (intEvent = Event_Error) or (intEvent = Event_Warning) Then WriteToEvtLog End If ' Write to local text file log WriteToTxtFile End Sub ' ' Write to event log ' Private Sub WriteToEvtLog() ' Create object Dim objShell Set objShell = Wscript.CreateObject("Wscript.Shell") ' Write out msg objShell.LogEvent intEvent, strAppName & " - " & strMsg ' Release memory Set objShell = nothing End Sub ' ' Write to log file ' Private Sub WriteToTxtFile() ' Declare variables Dim objFso Dim objFile ' Open the file Set objFso = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(strFileName, File_Append, True) ' Write the message objFile.WriteLine Now() & " - " & strMsg ' Close the file objFile.Close Set objFile = Nothing Set objFso = Nothing End Sub End Class