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:
#serilog + @getseq_net and #xamarin with event based, structured logging = heavenly. @nblumhardt amazing. pic.twitter.com/6DSNP25BYd— Geoffrey Huntley (@GeoffreyHuntley) August 17, 2016
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.
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
Logger.Dispose() when the application/activity exits.