SendLogMessage Example

This example demonstrates calling MessageLog2.SendLogMessage two different ways: Sending a plain text message with extra information to the local log; and sending a template based message with extra information to a server's log.  The sample also demonstrates using the MessageHelper interface to build the extra information consistently.

 

 

Build the SendLogMessage example as follows:

1. Create a new project and add a reference to the PISDK library.

2. Add the visual elements as shown in the picture. Make sure the numbered element names (label1, list1, &ldots;) match those shown.

3. Cut and paste the code below into the project.

   
   
Option Explicit

Private Sub Command1_Click()
On Error GoTo eh
   Dim msg2 As MessageLog2
   Set msg2 = PISDK.MessageLog
   Dim nvsTemplateParams As New NamedValues
   nvsTemplateParams.Sorted = False
   nvsTemplateParams.Add "1", "Test of local message without a template but with extra message parameters"
   Dim nvsMessageParams As New NamedValues
   Dim msgsndnms As IMessageSendNames
   Set msgsndnms = msg2
   nvsMessageParams.Add msgsndnms.Category, "My category"
   nvsMessageParams.Add msgsndnms.SeverityOverride, mscWarning
   msg2.SendLogMessage 0, nvsTemplateParams, nvsMessageParams
Exit Sub
eh:
   MsgBox Err.Description
End Sub

Private Sub Command2_Click()
On Error GoTo eh
   Dim msg2 As MessageLog2
   Dim srv As Server
   Set srv = Servers(Text1.Text)
   Dim cnxn As New Connections
   cnxn.Login srv
   Set msg2 = srv.MessageLog
   Dim nvsTemplateParams As New NamedValues
   nvsTemplateParams.Sorted = False
   Dim id As Long

   ' Build the template parameters
   id = 2065
   '  template args for 2065
   nvsTemplateParams.Add "1", "Example Archive Type"
   nvsTemplateParams.Add "2", "c:\right here\myarchive.dat"
   nvsTemplateParams.Add "3", CLng(33)
   nvsTemplateParams.Add "4", "Percent"
   nvsTemplateParams.Add "5", "42"
   Dim strtemp As String
   strtemp = Chr$(10) + Chr$(13) ' Build a new line character
   nvsTemplateParams.Add "6", strtemp
   nvsTemplateParams.Add "7", CLng(-12001)

   ' Now build some extra message parameters
   Dim nvsMessageParams As New NamedValues
   Dim msgsndnms As IMessageSendNames
   Set msgsndnms = msg2.MessageSendNames
   nvsMessageParams.Add msgsndnms.Priority, CLng(7)
   nvsMessageParams.Add msgsndnms.Source1, "Templated message test"
   nvsMessageParams.Add msgsndnms.SeverityOverride, mscError
   
   msg2.SendLogMessage id, nvsTemplateParams, nvsMessageParams
   Exit Sub
eh:
   MsgBox Err.Description
End Sub

The message template description file PIMessageDefinitions.htm in the PIPC\Help directory contains the following text for message ID 2065:

 

2065 Message: %1 %2 is %3 %4 (id: %5) %6%7
Severity: Information
Keywords:
Parameters:
      %1 = ArchiveType       Type: String
      %2 = Path       Type: String
      %3 = AmountFull       Type: Int32
      %4 = AmountFullUnits       Type: String
      %5 = ArchiveID       Type: String
      %6 = OptionalNL       Type: String
      %7 = OptionalStatus       Type: Status
Enabling Operational Intelligence