Partager via


Using Logging in Lync 2010 Controls

Use the LogListener object to record logging information in Microsoft Lync 2010 Control applications, for both Microsoft Silverlight and Microsoft Windows Presentation Foundation (WPF). For more information, see Lync 2010 Controls Walkthroughs. Also consider using Windows Event Logging for Lync. For more information, see How to use logging to troubleshoot Microsoft Lync Online installation issues.

Important

When logging is used in WPF or Silverlight applications, personal information such as telephone numbers can appear in logs. To protect confidential information, ensure logs are saved to secure locations.

In Silverlight applications, I/O operations typically are restricted to isolated storage and do not use the file system of the operating system. It is possible to work around this restriction by logging to a web service, or by using COM to access the local file system.

Adding Logging

To add logging in a Lync 2010 Control application, create one or more listener objects derived from the LogListener class. Then use the AddListener method on the Logger object to add each listener to the Listeners collection.

Use the LogListener.Categories property to filter log entries. Individual listeners can be filtered by different categories. Categories are defined by the developer.

LogListener Object

LogListener has a default constructor, and a constructor with parameters. The Write method on each LogListener object added to the Listeners collection is called when an event is processed. Developers should add code to the Write method to write to a web service, the Event Viewer, or another kind of storage.

// Sample implementation of the LogListener class
class MyListener : LogListener 
{
  // Constructor
  public MyListener()
  {}

  // Constructor
  public MyListener(LogLevel myLevel, string[] categories)
  {}

  // Write method
  public override void Write(LogEntry myEntry)
  {}
}

LogListener Parameters

Parameter

Description

Categories

An array of strings that specify the categories for a log entry, or a null reference. In Microsoft Visual Basic, the parameter value is Nothing.

Level

Gets an enumerated value that represents the severity of the event. The type is a LogLevel enumeration.

AddListener Method

Use the AddListener method to add a LogListener to the Listeners collection as shown in the following example. Listeners is a read-only collection derived from ReadOnlyCollection.

Logger.AddListener(MyListener);

Filtering Logging Output

Use the Level property to limit the log entries that appear in logging output. Log entries that do not match the setting of the Level property are ignored. Level is a property on the Logger, LogEntry, and LogListener objects. Level signifies the severity of the event. Filtering is performed based on severity, first by the Logger, then by the LogListener, and finally by the LogEntry object. For example, if Logger.Level is set to Error, LogListener and LogEntry receive error messages and all settings for LogListener and LogEntry are ignored. There are five available levels, in order of perceived severity:

  • Off

  • Verbose

  • Info

  • Warning

  • Error

To change the log level, set the Level property on the Logger, LogListener, and LogEntry objects.

// Set the level on the Logger object
Logger.Level = LogLevel.Info;

// Set the level on the LogEntry object
myEntry.Level = LogLevel.Error;

// Set the level on the LogListener object
MyListener.Level = LogLevel.Warning;

Writing Log Entries

To write log entries, first override the Write and WriteExtended methods. In the event handlers, call the Write or WriteExtended methods on the Logger object. These methods will use the Write method on the LogListener objects to write logging data.

Logging in WPF Applications

Use the TraceLogListener object to provide trace output in Lync 2010 Control WPF applications.

See Also

Concepts

Walkthrough: Add Logging to a Lync Controls Application

Walkthrough: Use Log Data to Debug Lync Control Applications

Other Resources

Lync 2010 Controls