2 Replies Latest reply on Apr 27, 2011 8:25 PM by mjarvis

    How can I write to a local PI-SDK Message log on a client machine

    mjarvis

      Hello Team,

       

      I am writing an application which reads data from PI, and I would like the application to write my own custom message when it completes. I have found examples to write to the PI Server, but I don't want to flood the server message log. I can't figure out how to obtain a window into the client message log or the client object. below is how I am writing to the server message log. My _PIServerRef is the PI Server which I am writing to.

       
      Dim ExtendedMessageLog As PISDK.MessageLog2 = Nothing
      Dim MessageParams As New PISDKCommon.NamedValues
      Dim TemplateParams As New PISDKCommon.NamedValues
      Dim NoTemplateParams As New PISDKCommon.NamedValues
      Dim MessageTemplate As String = "Date/Time: {0}, ID: {1}, Source: {2} --- {3}"
      Dim MessageString As String = String.Empty
      Dim ID As Int32
      
      'Get pointer to MessageLog2 Interface
      'With a pointer to any interface on the object, you can then call
      'QueryInterface to retrieve any other interface the object supports
      ExtendedMessageLog = DirectCast(_PIServerRef.MessageLog, PISDK.MessageLog2)
      
      'Build the template parameters
      ID = 1
      'Templage args for 2065
      TemplateParams.Sorted = False
      TemplateParams.Add("1", "Example archive type")
      TemplateParams.Add("2", "C:\here\myarchive.dat")
      TemplateParams.Add("3", 33)
      TemplateParams.Add("4", "%")
      TemplateParams.Add("5", "42")
      TemplateParams.Add("6", Environment.NewLine)
      TemplateParams.Add("7", -12001)
      
      'Build extra message parameters        
      MessageParams.Add(ExtendedMessageLog.MessageSendNames.Category, "My Category")
      MessageParams.Add(ExtendedMessageLog.MessageSendNames.Source1, _
                                                                        "Templated message test")
      'MessageParams.Add(ExtendedMessageLog.MessageSendNames.SeverityOverride, _
      '                                          PISDK.MsgSeverityConstants.mscError)
      
      'Send it to the PI Server Message Log
      ExtendedMessageLog.SendLogMessage(ID, TemplateParams, MessageParams)
      

       

        • Re: How can I write to a local PI-SDK Message log on a client machine

          There is a PISDK.MessageLog property.  You need to assign to the MessageLog2 interface to get access to sendLogMessage.

            • Re: How can I write to a local PI-SDK Message log on a client machine
              mjarvis

              That was easy enough, thanks for the help! I needed to grap the global PISDK object for the application (_PISDK) and assign that for the directcast. Solved!

               
              Public Class PISDKAppApr21
              
                   Public _SelfReference As PISDKAppApr21
                   Public _PISDK As New PISDK.PISDK
              
                   ..
              
                   Dim ExtendedMessageLog As PISDK.MessageLog2 = Nothing
                   Dim MessageParams As New PISDKCommon.NamedValues
                   Dim TemplateParams As New PISDKCommon.NamedValues
                   Dim NoTemplateParams As New PISDKCommon.NamedValues
                   Dim MessageTemplate As String = "Date/Time: {0}, ID: {1}, Source: {2} --- {3}"
                   Dim MessageString As String = String.Empty
                   Dim ID As Int32
              
                   'Get pointer to MessageLog2 Interface
                   'With a pointer to any interface on the object, you can then call
                   'QueryInterface to retrieve any other interface the object supports
                   ExtendedMessageLog = DirectCast(_PISDK.MessageLog, PISDK.MessageLog2)
              
                   'Build the template parameters
                   ID = 1
                   'Templage args for 2065
                   TemplateParams.Sorted = False
                   TemplateParams.Add("1", "Example archive type")
                   TemplateParams.Add("2", "C:\here\myarchive.dat")
                   TemplateParams.Add("3", 33)
                   TemplateParams.Add("4", "%")
                   TemplateParams.Add("5", "42")
                   TemplateParams.Add("6", Environment.NewLine)
                   TemplateParams.Add("7", -12001)
              
                   'Build extra message parameters        
                   MessageParams.Add(ExtendedMessageLog.MessageSendNames.Category, "My Category")
                   MessageParams.Add(ExtendedMessageLog.MessageSendNames.Source1, _
                                                                                     "Templated message test")
                   'MessageParams.Add(ExtendedMessageLog.MessageSendNames.SeverityOverride, _
                   '                                          PISDK.MsgSeverityConstants.mscError)
              
                   'Send it to the PI Server Message Log
                   ExtendedMessageLog.SendLogMessage(ID, TemplateParams, MessageParams)