NotesLog class sample code from Maximizing Agent Performance webcast
This tip containst the sample code for the NotesLog class mention in the Hatter/Bankes webcast.
As promised this is the NotesLog class sample code so many of you wanted from the webcast
"Maximizing Agent Performance" with Dave Hatter and Tim Bankes.
The following sample code is presented in LotusScript and Java.
LOTUSSCRIPT
Sub Initialize ' Last mods 0304014 - Dave Hatter - dhatter@libertastechnologies.com - www.libertastechnologies.com ' This code will write log messages to a text file. On Error Goto Errhandler Dim nsCurrent As NotesSession Dim nlogCurrent As NotesLog Set nsCurrent = New NotesSession Dim strMsg As String, strNL As String Set nLogCurrent =nsCurrent.CreateLog ( nsCurrent.CurrentAgent.Name ) Call nlogCurrent.OpenFileLog ("c:davetestLS.txt") ' This will write to the local drive, insert a valid path for your environment here ' **** Enable/Disable logging here nLogCurrent.LogErrors=True nLogCurrent.LogActions=True nLogCurrent.LogAction("*** Starting ***") strNL=Chr(10) & Chr(13) With nsCurrent strMsg="Notes Version:" & .NotesVersion & " " & .NotesBuildVersion nLogCurrent.LogAction ("Notes Version:" & .NotesVersion & " " & .NotesBuildVersion) strMsg=strMsg & strNL & "Platform:" & .Platform nLogCurrent.LogAction ("Platform:" & .Platform) strMsg=strMsg & strNL & "User Name:" & .UserName nLogCurrent.LogAction ("User Name:" & .UserName) strMsg=strMsg & strNL & "Database Name:" & nsCurrent. CurrentDatabase.Title nLogCurrent.LogAction ("Database Name:" & nsCurrent. CurrentDatabase.Title) strMsg=strMsg & strNL & "Database File:" & nsCurrent. CurrentDatabase.FilePath nLogCurrent.LogAction( "Database File:" & nsCurrent. CurrentDatabase.FilePath) strMsg=strMsg & strNL & "Agent Name:" & nsCurrent. CurrentAgent.Name nLogCurrent.LogAction ("Agent Name:" & nsCurrent. CurrentAgent.Name) Msgbox strMsg,64, "Notes Information" End With nLogCurrent.LogAction ("*** Ending ***") nLogCurrent.Close Exit Sub Errhandler: Call nlogCurrent.LogError (Err,"An Error:" & Error$ & "( " & Cstr(Err) & ") has occured on line " & Cstr(Erl)) nlogCurrent.LogAction ("*** Abending ***") nlogCurrent.Close Exit Sub End Sub
JAVA
import lotus.domino.*; // Last mods 0304014 - Dave Hatter - dhatter@libertastechnologies.com - www.libertastechnologies.com // This code will write log messages to a text file. public class JavaAgent extends AgentBase { public void NotesMain() { try { Session nsCurrent = getSession(); AgentContext nacCurrent = nsCurrent.getAgentContext(); Log nlogCurrent = nsCurrent.createLog(nacCurrent. getCurrentAgent().getName()); nlogCurrent.openFileLog ("c:davetestJava.txt"); //' This will write to the local drive, insert a valid path for your environment here nlogCurrent.logAction("*** Starting ***"); System.out.println("Notes Version:" + nsCurrent.getNotesVersion()); nlogCurrent.logAction ("Notes Version:" + nsCurrent. getNotesVersion()); System.out.println("Platform:" + nsCurrent.getPlatform()); nlogCurrent.logAction("Platform:" + nsCurrent.getPlatform()); System.out.println("User Name:" + nsCurrent.getUserName()); nlogCurrent.logAction("User Name:" + nsCurrent.getUserName()); System.out.println("Database Name:" + nacCurrent.getCurrentDatabase ().getTitle()); nlogCurrent.logAction("Database Name:" + nacCurrent.getCurrentDatabase() .getTitle()); System.out.println("Database File:" + nacCurrent.getCurrentDatabase(). getFilePath()); nlogCurrent.logAction("Database File:" + nacCurrent.getCurrentDatabase(). getFilePath()); System.out.println("Agent Name:" + nacCurrent.getCurrentAgent().getName()); nlogCurrent.logAction("Agent Name:" + nacCurrent.getCurrentAgent().getName()); nlogCurrent.logAction("*** Ending ***"); nlogCurrent.close(); } catch(Exception e) { e.printStackTrace(); } } }
Start the conversation
0 comments