Debug and Trace Messages

MSRS provides an interface for viewing error and informational messages returned by a service (refer to Figure 2-8). Filters allow you to restrict the types of messages displayed. For example, if you only select the Error check box, then only messages marked with a trace level of error will appear in the list. You can also restrict the output to display messages generated from a certain source or category.

To log the messages that appear in the console output service, you will need to call one of the following logging functions provided with the DSSP service base:

  • LogInfo. Logs message with a trace level of info. These messages will appear with two stars and a yellow background for the level column.

  • LogError. Logs messages with a trace level of error. These messages will appear with three stars and a pink background for the level column.

  • LogWarning. Logs messages with a trace level of warning. These messages will appear with no stars and no background color.

  • LogGroups. Logs categories and can be used when logging messages to assign them to certain categories. This allows you to restrict what messages are displayed in the Debug And Trace Messages window.

  • LogVerbose. Used to log messages generated from system services only.

The Debug And Trace Messages window, which displays logged information from your service.

Figure 2-8. The Debug And Trace Messages window, which displays logged information from your service.

A trace level is used to indicate the type of message to log. DssInfo provides a way to log messages with a trace level of info. Messages logged as informational will appear with a yellow background in the level column (refer to Figure 2-8). You can log a message as informational by using code such as the following:

LogInfo("This is the state for my service " + _state.OutputMsg);

You can view details for a message by clicking the arrow that appears in the View column. This will display additional information such as the time the message was posted and from what service. For example, the detail for the informational message "This is information posted from my service Hello World" will appear as follows:

Message

This is information posted from my service Hello World

Category

StdOut

Level

Info

Time

2007-07-16T12:42:48.344-05:00

Subject

This is information posted from my service Hello World

Source

http://sara-pc:50000/servicetutorial1

CodeSite

Void Start()() at line:72, fileC:Microsoft Robotics Studio (1.5)samplesServiceTutorialsTutorial1CSharpServiceTutorial1.cs

The other commonly logged message is an error. When performing functions that modify state, it is a good idea to include checks to ensure that the code updated successfully. If it did not, you can add code to post an error message along with the fault exception using the LogError function. For example, the following code from Service Tutorial 3 will save the state only if it encounters no errors (otherwise, it will post the error message to the log):

yield return Arbiter.Choice(
   base.SaveState(_state),
   delegate(DefaultReplaceResponseType success) { },
   delegate(W3C.Soap.Fault fault)
   {
       LogError(null, "Unable to store state", fault);
   }
 );

The error message will appear in the Debug And Trace Messages window with a pink background and three stars as the level. The detail for the exception will include information associated with the exception and can be seen by clicking the arrow in the View column.

MSRS provides three trace levels: Informational, Warning, and Error. For service authors who wish to create their own trace levels, MSRS allows them to add new trace switches using the System.Diagnostics.TraceSwitch class. This class is part of the .NET Framework and is not specific to MSRS. You can get more information about creating new trace switches through the following URL: http://msdn2.microsoft.com/en-us/library/system.diagnostics.traceswitch(vs.71).aspx.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.177.14