![]() |
![]() |
|
||||||||||||||||
|
![]() | ||
![]() | ![]() Logging Application Activity Back to Main Menu Introduction Introduction to Logging Application Activity Creating an Application Activity Log Creating an Application Activity Log Database Logging Information to a Database Creating a NotesLog Object Opening a NotesLog Object Logging Actions Logging Errors Exercise Logging Application Activity Exercise Solution Introduction Introduction to Logging Application Activity A NotesLog object can be used to record actions and errors that occur in scripts. This information can be stored in one of the following ways: In this Learning Byte, you will learn how to create and populate a Notes database with application activity information. Back to Table of Contents Creating an Application Activity Log Creating an Application Activity Log Database To log script activity in a Notes database with the NotesLog object, do the following: 1. Create a Notes log database from the ALOG4.NTF template. 2. Create a new NotesLog object in the script of the application whose activity you want to record. 3. Open the Log database. 4. Record specific activities or errors. Back to Table of Contents Logging Information to a Database Creating a NotesLog Object Once you have created the database you will use for logging, the next step in logging application activity is to create the NotesLog object. This procedure is similar to creating other LotusScript objects. Syntax Dim variableName as New NotesLog(scriptName$) or Set myLog = New NotesLog(scriptName$) In this example, scriptName$ identifies the script whose actions and errors you want to log. It is used in the application activity log database to categorize the log entries. You should specify a unique name for each script in your application, so you can easily identify which script recorded which entry. Example Assume you have scripts attached to a query button and an update button. Behind the query button, you might set up a NotesLog object as follows: Dim myLog as New NotesLog("Query") Behind the update button, you might set it up like this: Dim myLog as New NotesLog("Update") Back to Table of Contents Opening a NotesLog Object The application activity log database must be opened before a script's activity can be logged. To open the database, use the following method: Call MyLog.OpenNotesLog(server$, dbfile$) When writing to a database, a new document is created for each action or error that is logged. Each document contains the following information: A script must have at least Reader access in order to open a database. If a script runs on a server, it cannot open a database on another server. An error will be generated if this is attempted. Back to Table of Contents Logging Actions You must explicitly direct a script to log an action in the NotesLog. Notes does not automatically record this information. Use the LogAction method to log an action. Syntax Call notesLog.LogAction(description$) In this example, description$ is a description of the action the script performed as you want it to appear in the log. Example Call myLog.LogAction("Processed document" + Cstr(count%)) Back to Table of Contents Logging Errors Use the LogAction method to log script errors. Syntax Call notesLog.LogError(code%, description$) In this example, code% is an integer indicating the error that has occurred. The description$ string describes the error as you want it to appear in the log. Example Call myLog.LogError(IsERR_NOTES_DATABASE_NOTOPEN,"Unable to open " & db.FileName) Back to Table of Contents Exercise Logging Application Activity Introduction In this exercise, you will set up a simple application activity log database. The Logging App Activity - Exercises database, Laaex.nsf, contains a form with a button that tries to open a view that does not exist. Instructions 1. Download this database to your notes/data directory and add it to your workspace. Logging App Activity - Exercises 2. Create an application activity log database based on the Agent Log template (ALOG4.NTF). Enter "agentlog.nsf" for the filename. 3. Open the Logging - Exercise form in the Logging App Activity - Exercises (Laaex.nsf) database. 4. In the Click event of the button, write a script that searches for the given view name.
6. Go back to the button's script and change the value of viewname to the name of the view that already exists. Test the LogAction method by repeating Step 5. Back to Table of Contents Exercise Solution Sub Click(Source As Button) viewName$ = "Wrong Viewname" Dim session As New NotesSession Dim db As NotesDatabase Dim view As NotesView Dim currentLog As New NotesLog("Logging Demo") Call currentLog.OpenNotesLog("","agentlog.nsf") Set db = session.currentdatabase Set view = db.GetView(viewName$) If view Is Nothing Then Call currentLog.LogError(0,"Unable to locate view: " + viewName$) Else Call currentLog.LogAction("Successfully located view: " + viewName$) End If Call currentLog.Close End Sub Back to Table of Contents |
![]() |
|||||
|