Reputation: 530
Is there any logging framework which supports Portable Class Library? I searched on Nuget but failed to find any.
Thanks,
Upvotes: 17
Views: 4770
Reputation: 2731
I had run into a similar situation where I needed to perform logging in my portable libraries in some sort of consistent manner. I had looked previously at Splat and Common.Logging and decided they were a bit too heavy for my needs (both are actually very solid logging frameworks though). So if you are interested in something a bit more light weight I have written a framework that supports all portable profiles (to 344 as of writing this) and provides a minimal footprint. The framework operates as a portable library that forwards on logging calls to a chosen adapter library (currently there are NLog and log4net adapters available on NuGet). Your platform entry point is then responsible for wiring up logging the way you normally would, and simply constructing an adapter and passing that reference down into portable land (a popular method would be to use dependency injection to provide the portable classes with access to the portable logging interfaces).
The project is not very active, but only because I haven't needed to add anything since its last update. I wrote another android adapter but haven't been doing any Xamarin coding since I wrote it. The code is extremely minimal, just the necessities to make logging pleasant and easy. This framework is even compatible with CF35 (though there is no official build for it), should anyone actually need it to operate to that extent.
Upvotes: 0
Reputation: 530
I'll answer my own question:
Common.Logging, a widely-used portable logging abstraction for .NET, became PCL compatible in early 2014 (around version 2.2.0). I used Common.Logging in most of my libraries (PCL and non-PCL) and it just works perfectly.
Upvotes: 4
Reputation: 8176
Check out Splat.
A library to make things cross-platform that should be
It's a small PCL library with some useful cross-platform classes including logging...
https://github.com/paulcbetts/splat/blob/master/Splat/Logging.cs
You can get it from NuGet.
Upvotes: 2
Reputation: 11
Because I also found no solution, I created my own here... https://portilog.wordpress.com/
Upvotes: 1
Reputation: 10620
Not sure, if there is logging framework targeting directly Portable Class Library, but nothing stops you from implementing logging in your PCL using Dependency Injection - create interface for logging service and implement it in all target platforms separately using your favorite, or even different libraries. You have then more control over specific logging settings - it's quite different approach for logging in .NET WPF app, WP8 app or Windows Store app.
Upvotes: 8