Raise Crimson Events from .NET Part 2 - The Manifest

It seems I got a little side tracked with these posts, but here goes the next one...

Our first task is to create an Instrumentation Manifest, which will contain the definitions for the channels, events and anything else our application will need to raise events. The Instrumentation Manifest is simply a XML file. Check out https://windowssdk.msdn.microsoft.com/library/default.asp?url=/library/en-us/wes/wes/eventmanifestschema_instrumentationmanifest_element.asp?frame=true for some pointers to the schema used.

In our example, we shall create our own channel for our events. We'll call this channel "Microsoft-Samples-CrimsonNetDemo/MyChannel". We will also write an event to the existing Application Log.

The <channels> section of the manifest defines the channels - here is ours:

 <channels>
   <importChannel chid="C1" name="Application" />
   <channel name="Microsoft-Samples-CrimsonNetDemo/MyChannel"       chid="C2"       symbol="MYCHANNEL"       type="Admin"/>
</channels>

We shall define 2 events, SIMPLE_EVENT and SIMPLE_EVENT2 - both will be based upon the same event template. The <events> section defines the events as shown here:

 <events>
   <event symbol="SIMPLE_EVENT" 
      template="SimpleEvent" 
      level="win:Informational"
      value="100" 
      version="1" 
      channel="C1" 
      message="$(string.SimpleMessage)"/>
   <event symbol="SIMPLE_EVENT2"
      template="SimpleEvent"
      level="win:Informational"
      value="101"
      version="1"
      channel="C2"
      message="$(string.SimpleMessage)"/></events>
  • Events are linked to the channel using the chid defined earlier in the channels section..
  • Value is the error number as seen in the event viewer.
  • Level is stolen from the winmeta.xml file

And the <templates> section defines the templates:

 <templates>
   <template tid="SimpleEvent">
      <data name="ExceptionMessage" inType="win:UnicodeString"/>
      <UserData>
         <SimpleEvent             xmlns="https://manifests.microsoft.com/win/2004/08/windows/simpleevent">
            <ExceptionMessage>%1</ExceptionMessage>
         </SimpleEvent>
      </UserData>
   </template>
</templates>

Finally we also use a string table (just for fun):

 <localization>
   <resources culture="en-US">
      <stringTable>
         <string id="SimpleMessage" value="The Mortgage Service Started %1">
         </string>
      </stringTable>
   </resources>
</localization>

Actually I say just for fun, but it belongs to the localization section - which you can probably guess allows us to define localized messages.

Here is our final manifest, which we'll call EventSchema.man

 <?xml version="1.0" encoding="UTF-16"?>
<assembly xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" 
   xmlns:xsd="https://www.w3.org/2001/XMLSchema"  
   xmlns="urn:schemas-microsoft-com:asm.v3">
   <localization>
      <resources culture="en-US">
         <stringTable>
            <string id="SimpleMessage" value="There is a message: %1" stringType="string"/>
         </stringTable>
      </resources>
   </localization>
   <instrumentation
      xmlns:xs="https://www.w3.org/2001/XMLSchema" 
      xmlns:win="https://manifests.microsoft.com/win/2004/08/windows/events"
      xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance">
      <events xmlns="https://schemas.microsoft.com/win/2004/08/events">
         <provider name="Microsoft-Samples-CrimsonNetDemo" 
            guid="{9c878495-5572-474e-97b6-ae8072b18037}" 
            symbol="PROV_CRIMSONDEMO" 
            resourceFileName="d:\CrimsonNetDemo\CrimsonNetSchema.dll" 
            messageFileName="d:\CrimsonNetDemo\CrimsonNetSchema.dll">
             <channels>
               <importChannel chid="C1" name="Application" />
               <channel name="Microsoft-Samples-CrimsonNetDemo/MyChannel" chid="C2" symbol="MYCHANNEL" type="Admin"/>
            </channels>
            <opcodes>
               <opcode name="myopcode" symbol="OP1" value="100"/>
            </opcodes>
            <templates>
               <template tid="SimpleEvent" message="$(string.SimpleMessage)">
                  <data name="ExceptionMessage" inType="win:UnicodeString"/>
                  <UserData>
                     <SimpleEvent xmlns="https://manifests.microsoft.com/win/2004/08/windows/simpleevent">
                        <ExceptionMessage>%1</ExceptionMessage>
                     </SimpleEvent>
                  </UserData>
               </template>
            </templates>
            <events>
               <event symbol="SIMPLE_EVENT" 
                  template="SimpleEvent" 
                  level="win:Informational"
                  value="100" 
                  version="1" 
                  channel="C1"
                  opcode="myopcode"
                  message="$(string.SimpleMessage)"/>
               <event symbol="SIMPLE_EVENT2"
                  template="SimpleEvent"
                  level="win:Informational"
                  value="101"
                  version="1"
                  channel="C2"
                  opcode="myopcode" 
                  message="$(string.SimpleMessage)"/>
            </events>
         </provider>
      </events>
    </instrumentation>
<assembly>

Next we'll turn this Manifest into a resource that can be used by our application and the event viewer...

This posting is provided "AS IS" with no warranties, and confers no rights.