Console Ouptut: my New Debugging and Testing tool for Windows

I have been working with a partner who wanted to get standard console output from a UWP app for debugging and testing purposes. Of course the easiest way get debugging output is by attaching a debugger like Visual Studio but in some cases that isn’t possible or practical. I just published an app, Console Output that enables other apps to send output text lines to it. There are some new capabilities in Windows 10 Anniversary Update that makes this possible:

  1. App Services that can run in the application’s process instead of in a background task 
  2. Remote Systems API that enables connecting apps across devices and platforms.

Destktop

On its own, Console Output doesn’t do anything special when you run it, but if you launch it from another app by activating the consoleoutput: protocol handler consoleoutput:?title=My app name you can then send text output to it with app services.

When you install and run Console Output, you will see a full code sample in C# showing how to launch Console Output with the Launcher.LaunchUriAsync() API and then open an AppServiceConnection communications channel for bi-directional communications with Console Output. The sample code is at the bottom of this article. Console Output is also enabled for remote activation so doing debugging and testing of devices nearby or through the cloud becomes possible as well. I have also shared the source code for a Console Output Tester app that demonstrates how an app might use Console Output.

Sample C# Code

using System;
using Windows.ApplicationModel.AppService;
using Windows.Foundation.Collections;
using Windows.System;

public class ConsolLoggingTester : IDisposable
{
private AppServiceConnection _appServiceConnection;

public ConsolLoggingTester()
{
InitializeAppServiceConnection();
}

    private async void InitializeAppServiceConnection()
{
// this is the unique package family name of the Console Ouput app
const string consoleOutputPackageFamilyName = "49752MichaelS.Scherotter.ConsoleOutput_9eg5g21zq32qm";

        var options = new LauncherOptions
{
PreferredApplicationDisplayName = "Console Output",
PreferredApplicationPackageFamilyName = consoleOutputPackageFamilyName,
TargetApplicationPackageFamilyName = consoleOutputPackageFamilyName,
};

        // launch the ConsoleOutput app
var uri = new Uri("consoleoutput:?Title=Console Output Tester&input=true");

        if (!await Launcher.LaunchUriAsync(uri, options))
{
return;
}

        var appServiceConnection = new AppServiceConnection
{
AppServiceName = "consoleoutput",
PackageFamilyName = consoleOutputPackageFamilyName
};

        var status = await appServiceConnection.OpenAsync();

        if (status == AppServiceConnectionStatus.Success)
{
_appServiceConnection = appServiceConnection;

// because we want to get messages back from the console, we
// launched the app with the input=true parameter
_appServiceConnection.RequestReceived += OnRequestReceived;
}
}

    public async void LogMessage(string messageText)
{
if (_appServiceConnection == null)
{
return;
}

        var message = new ValueSet
{
["Message"] = messageText
};

        await _appServiceConnection.SendMessageAsync(message);
}

    public void Dispose()
{
if (_appServiceConnection != null)
{
_appServiceConnection.Dispose();
_appServiceConnection = null;
}
}

    private void OnRequestReceived(
AppServiceConnection sender,
AppServiceRequestReceivedEventArgs args)
{
var message = args.Request.Message["Message"] as string;

        // handle message input from Console Ouptut app
}
}

Links

Please tell me if you start using Console Output and if you find it useful!