Use the LogListener object to record logging information in Microsoft Lync Control applications, for both Microsoft Silverlight and Microsoft Windows Presentation Foundation (WPF). For more information, see the walkthrough topics under Lync Controls Walkthroughs .

Important note 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 written 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 Controls 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 type of storage.

  Copy imageCopy Code
// 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




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 .


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 code example. Listeners is a read-only collection derived from ReadOnlyCollection.

  Copy imageCopy Code

Filtering Logging Output

Use the Level property to limit which log entries 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. The Level signifies the severity of the event. Filtering is performed on the basis of severity, first by the Logger then the by LogListener , and finally by the LogEntry object. So for example if Logger.Level is set to Error , LogListener and LogEntry only receive error messages regardless of their settings. 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.

  Copy imageCopy Code
// 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 Control WPF applications.

See Also