Announcing Serilog.Sinks.Xamarin


1 minute read - suggest an edit

Serilog has, for quite a time now been my favourite logging library for .NET because unlike other logging libraries, Serilog is built with structured event data in mind which is incredibly powerful.

Despite using Serilog exclusively server-side with event-based logging for a couple of years now, I’ve only just started exploring applying this theory to the domain of mobile phone applications.

After a day of playing around, my imagination is running wild at all of the possibilities:

Today I’m releasing a first of many add-ins to come for Serilog; this one is a sink that writes events to the console of Xamarin.iOS (NSLog) / Xamarin.Android (AndroidLog) applications. It’s now available via NuGet or GitHub.

Getting started

Install from NuGet

Install-Package Serilog.Sinks.Xamarin -Pre

When using Xamarin.iOS

Log.Logger = new LoggerConfiguration()
    .WriteTo.NSLog();
    .CreateLogger()

When using Xamarin.Android

Log.Logger = new LoggerConfiguration()
    .WriteTo.AndroidLog();
    .CreateLogger()

Within your portable class libary or within your application

Log.Information("This will be written to either NSLog or AndroidLog");

Because the memory buffer may contain events that have not yet been written to the target sink, it is important to call Log.CloseAndFlush() or Logger.Dispose() when the application/activity exits.

Related Posts

ReactiveUI v7.2.0 released

Learn these three buttons

Announcing ReactiveUI virtual community meetups

ReactiveUI v7.1.0 released

ReactiveUI v7.0.0 released

Semantic Versioning of Xamarin Applications

Announcing Cake.Raygun

Announcing Cake.AppleSimulator

Example of Xamarin iOS with Cake

Example of Xamarin Android with Cake