Search code examples
loggingxamarinlog4netseriloglogentries

Logentries + Xamarin = how?


The main question is: how to integrate Logentries in a Xamarin-based mobile app? Below two ways are taken into consideration: Serilog and log4net.

Logentries supports Android, iOS, WP natively but not when those APIs are proxified using Xamarin. Serilog is an elegant C# wrapper around Logentries API but there is a problem installing all of its needed components along with Xamarin's ones in the same project. Visual Studio is being used as IDE and NuGet as package manager. The packages that I think should be installed using NuGet in are Serilog, Serilog.Mobile, Serilog.Sinks.Logentries. When creating Android application using Xamarin the Mono.Android module is being used. Serilog coexists with Mono.Android perfectly well but Serilog.Mobile and Serilog.Sinks.Logentries don't:

Error: Could not install package 'Serilog.Sinks.Logentries 1.5.8'. You are trying to install this package into a project that targets 'Xamarin.iOS,Version=v1.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

The error message is the same for Serilog.Mobile.

When using Xamarin.iOS the only incompatible module happens to be Serilog.Sinks.Logentries:

Error: Could not install package 'Serilog.Sinks.Logentries 1.5.8'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v6.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

Saw that there is a Xamarin Serilog "sink". written by the same person who've created the Logentries' one. From what I see it is just porting the Serilog library and provide convenience loggers for the Android's Log class and iOS' NSLog:

ILogger androidLogger = new Serilog.LoggerConfiguration().WriteTo.AndroidLog().CreateLogger();
ILogger iosLogger = new Serilog.LoggerConfiguration().WriteTo.NSLog().CreateLogger();

So the first question is if Serilog is about to be used for the Xamarin-based app how could that happen?

log4net is another option for a Logentries C# port but probably again not for Xamarin but for desktop applications. Just investigating it as well and as obvious there are some ports for iOS.

If you could recommend me the correct approach to use Logentries in tandem with Xamarin, it would be great.


Solution

  • It sounds like you will need to download the source of the Logentries sink and recompile it for Xamarin yourself. (Serilog's support for Xamarin platforms is minimal because of the difficulty obtaining tools/running builds without having to purchase a license. If you can make an improvement to the https://github.com/serilog/serilog-sinks-logentries repository a PR enabling Xamarin support would no doubt be welcomed there.)