Enabling Logging

The Library logs informational messages for debugging purposes.

Logging is implemented using the event model of the .NET framework. The WTLogger object triggers LogMessageEvent events. Your application can assign a handler to process these events. Your event handler receives an argument containing the message string, and message type. To enable logging:
  1. Configure the Library to enable events.
    1. Enable additional logging by editing webtrends.xml to set wt_dc_debug to true:
      <string name="wt_dc_debug">true</string>
  2. Register an event handler to capture events.
    1. Add the following code to your MainPage constructor (MainPage.xaml.cs).

      In Silverlight:

      // Constructor
      public MainPage()
      {
      	InitializeComponent();
      
      	WTLogger.LogMessageEvent += (o, args) =>
      	{
                      // write log message to debugger
      		Debug.WriteLine(args.Message);
      	};
      .
      .
      .
      }

      In XNA:

      public Game1()
      {
      	// Your constructor functionality here
      	.
      	.
      	.
      
      	WTLogger.LogMessageEvent += (o, args) =>
      	{
      		Debug.WriteLine(args.Message);
      	};
      .
      .
      .
      }

The args.Message member contains the log message. In the example, Debug.Writeline is used, but you can choose how to capture and use the log message.

The logging levels are:
  • ERROR
  • WARNING
  • INFO
  • DEBUG
The args.LogLevel member contains bit fields indicating the type of message. You may use this to filter on specific types. For example, to log only DEBUG and ERROR message types using Silverlight:
WTLogger.LogMessageEvent += (o, args) =>
{
     // only include DEBUG and ERROR messages
     if ((args.LogLevel & (WTLogLevel.DEBUG | WTLogLevel.ERROR)) > 0)
     {
          // write log message to debugger
          Debug.WriteLine(args.Message);
     }
};