Skip to content
Grigory Perepechko edited this page Nov 22, 2015 · 20 revisions

XLog - Minimalistic logging PCL library for (.NET, WP8, UWP, Xamarin iOS, Xamarin Android)

In the last project i participate in, we have all logic in PCL libraries (78 profile). 1.5 years ago there was only one PCL logger – MetroLog. It was partially copied from log4net/NLog and contained too much async/await logic (mostly IO related), which is too expensive for mobile devices, especially if app performs very detailed logging as our app does.

So we outlined few goals for a perfect logging library:

  • Very small in terms of lines of code.
  • Minimal footprint on IOS IPA size
  • Very fast with minimal possible amount of memory allocations
  • No dependencies except for .NET
  • Support of WP8, Xamarin, UWP
  • Support categories
My colleague Oleg Ilyin wrote an implementation that satisfied those goals, which i optimized to reach acceptable performance and uploaded to github.
  • We have a library that has ~200 lines of code according to Visual Studio metrics.
  • NET dll size is ~20kb, IOS binary footprint is less than 50kb for ARMv7+ARM64.
  • Logging one message to file produces 2 memory allocations, which is much less that NLogs 25, and is ~20 times faster in terms of CPU time (FileTarget, Console app sample).
Example of logging:
 private static readonly Logger Log = LogManager.Default.GetLogger("ClassName");
 // ....
 for (int i = 0; i < 100000; i++)
     Log.Info(“Hello world!”);

Example of output:

 16:18:17:439|INFO|1|MainController|Hello world!

Example of init logic

 private static void InitLogger()
 {
     var formatter = new LineFormatter();
     var logConfig = new LogConfig(formatter);
     var target = new SyncFileTarget(@”D:\Log.log”);
     logConfig.AddTarget(LogLevel.Trace, LogLevel.Fatal, target);
     LogManager.Init(logConfig);
 }
Clone this wiki locally