Building your own logging target to capture logs generated by the analytics plugin is straight forward. You simply need to create a class that implements Microsoft.VideoAnalytics.ILoggingTarget. Note: if your app is a Windows 8 JavaScript app you just need to add a WinRT class library to your solution and built the logging target implementation in C#, VB, or C++.

Building an ILoggingTarget

ILoggingTarget is a very simple interface with only one method:
namespace Microsoft.VideoAnalytics
{
    /// <summary>
    /// An interface to allow an object to become a target of logging events.
    /// </summary>
    public interface ILoggingTarget
    {
        /// <summary>
        /// Called to pass a new log to the target.
        /// </summary>
        /// <param name="log">The log object that was generated.</param>
        void LogEntry(ILog log);
    }
}
Once you register your implementation as a logging target, it will automatically receive all logs generated.

Using and understanding the logs

Each log implements ILog and can be cast to a specific log type to find out more details. There are dozens of different types of logs generated and even more if you wire up the AdaptiveMonitor (see next section below for more details).

A typical way to read and utilize the logs received typically involves checking the object type and depending on the type, casting it to it's true form and reading it's high level properties.

Here's an example of what the code may look like:
public void LogEntry(ILog log)
{
    if (log is PerceivedBandwidthLog)
    {
        var typedLog = (PerceivedBandwidthLog)log;
        var chart = Charts.First(c => c.QualityAttribute == QualityCharts.PerceivedBandwidth);
        chart.AddDataPoint(typedLog.PerceivedBandwidth / (1024 * 8));
    }
    else if (log is BufferSizeLog)
    {
        var typedLog = (BufferSizeLog)log;
        ChartViewModel chart = null;
        if (typedLog.StreamType == "audio")
        {
            chart = Charts.First(c => c.QualityAttribute == QualityCharts.AudioBufferSize);
        }
        if (typedLog.StreamType == "video")
        {
            chart = Charts.First(c => c.QualityAttribute == QualityCharts.VideoBufferSize);
        }
        if (chart != null)
        {
            chart.AddDataPoint(typedLog.BufferSize);
        }
    }
    else if (log is ChunkDownloadLog)
    {
        var typedLog = (ChunkDownloadLog)log;
        ChartViewModel chart = null;
        if (typedLog.StreamType == "audio")
        {
            chart = Charts.First(c => c.QualityAttribute == QualityCharts.AudioDownloadLatencyMilliseconds);
        }
        if (typedLog.StreamType == "video")
        {
            chart = Charts.First(c => c.QualityAttribute == QualityCharts.VideoDownloadLatencyMilliseconds);
        }
        if (chart != null)
        {
            chart.AddDataPoint(typedLog.DownloadTimeMs);
        }
    }
    else if (log is BitrateChangedLog)
    {
        var typedLog = (BitrateChangedLog)log;
        var chart = Charts.First(c => c.QualityAttribute == QualityCharts.BitRate);
        chart.AddDataPoint(typedLog.Bitrate);
    }
    else if (log is BufferingChangedLog)
    {
        var typedLog = (BufferingChangedLog)log;
        var chart = Charts.First(c => c.QualityAttribute == QualityCharts.IsBuffering);
        chart.AddDataPoint(typedLog.IsBuffering ? 1 : 0);
    }
    else if (log is StreamLoadedLog)
    {
        var loadLog = log as StreamLoadedLog;
        var bitrateChartData = Charts.First(vm => vm.QualityAttribute == QualityCharts.BitRate);
        bitrateChartData.MaxValue = loadLog.MaxBitrate;
    }
}

Registering your custom logging target

To connect your logging target to the player framework, you only need one line of code:
In JavaScript:
Microsoft.VideoAnalytics.LoggingService.current.loggingTargets.append(new MyNamespace.MyLoggingTarget());
In C#:
LoggingService.Current.LoggingTargets.Add(new MyLoggingTarget());

More data: add your own logs

It is equally easy to add your own data. Simply create a new ILog implementation for each log type you want to create and pass them into the logging service via:
In JavaScript:
Microsoft.VideoAnalytics.LoggingService.current.log(new MyNamespace.MyLog());
In C#:
LoggingService.Current.Log(new MyLog());

Logs can also have data attached to them automatically by logging through the AnalyticsPlugin. Logs sent to this class will automatically be stamped with additional session and media specific data before they are sent to the LoggingService. To do this:
In JavaScript:
mediaPlayer.AnalyticsPlugin.log(new MyNamespace.MyLog());
In C#:
analyticsPlugin.Log(new MyLog());

Note: add to the AnalyticsPlugin.MediaData and AnalyticsPlugin.SessionData dictionaries to include additional data that you want attached to each log. This is particularly useful for VideoID, ...etc.

More data: Connecting the AdaptiveMonitor for Smooth Streaming information

See the Audience Insight getting started guide to learn about how to capture smooth streaming heuristics and diagnostics data.

More data: Capturing unhandled exceptions

See the Audience Insight getting started guide to learn about how to capture unhandled exceptions.

More data: Using the TrackingPlugin

The tracking plugin is a great way to know when specific milestones or playback positions have been reached by your user. These plugins can also generate logs that are automatically captured by the analytics plugin. All you have to do is make sure the events you are tracking have the Area property set to "Analytics".
See the Tracking plugin documentation to learn about how to create playback and position events to track.

Your app can be a logging target too.

Instead of filtering, serializing and sending logs to a server, it is also possible to consume these logs locally. This can be useful for displaying diagnostic information in your app to help debug playback issues. As a proof of concept, we ported the Silverlight Health Monitor to Windows 8 to demonstrate a novel use for this approach. Here you can see a subset of the data being logged and displayed into a real time monitor within your application.

healthmonitor.png

Last edited Apr 12, 2013 at 11:09 PM by timgreenfield, version 5