Viewing logs from C# mobile apps

Dec 10, 2014 • nblumhardt

I’ve recently been writing some code for Windows Phone, cross-compiled for iOS and Android using the Xamarin tools.

The app does quite a lot of background processing, but during development and testing it started to feel like a black box. A few lines of code got events posting from Serilog via HTTP to a Seq instance running on my development machine.

I liked the results so much tonight I decided make a quick experimental port of Serilog.Sinks.Seq to a portable class library:

You can install it in your Windows Phone or Xamarin project directly from NuGet:

And write log messages from your mobile app straight back to Seq running on your development machine:

Log.Information("Hello, Seq!");

Single-user installs of Seq are free, so you can use this during development even if your team uses something else for production logging.

Emulator Networking

You’ll need to use the address of your development machine assigned by the emulator - don’t try connecting to Seq as localhost - this will loop back to the emulator itself. Windows Phone lets me get at my desktop via "http://169.254.80.80:5341" while Android works with "http://10.0.2.2:5341". (5341 is the default port Seq listens on.)

I haven’t tested this on iOS yet - it’s possible you’ll find issues there if you beat me to it.

Why ‘Experimental’?

It’s somewhat uncharted territory for me - Serilog is still working the last kinks out of iOS/Android support, and the Serilog features that the sink relies on aren’t all portable because of missing features like System.Threading.Timer. Eventually I hope the code here can be feed back into Serilog and improve this.

Where’s the code?

Here, on GitHub. Please send a PR if you find any improvements to make. Enjoy!