Re-Introducing Caliburn.Micro.Logging

It has been a long time since I upgraded this library, and the .NET development world has shifted a bit in that time. One of the key changes is the move to Portable Class Libraries, and Caliburn.Micro is one the libraries making that change. I have decided to follow suit and make the core Caliburn.Micro.Logging library portable. This, of course, has creating some significant breaking changes, so please look over the changes list below.

I am re-introducing this, since my other posts on this are quite old, and seem a bit dated. If you are interested in the other posts, here is the list of related posts:

Changes

  • Upgraded from Calibrun.Micro to Calibrun.Micro.Core 2.0.0-beta2
  • Converted Caliburn.Micro.Logging to a Portable Class Library
  • Removed TraceLogger [breaking]
  • Dropped support for Silverlight 45 and Windows Phone 7.1 [breaking]
  • Added a strong name
  • Upgraded solution / project to Visual Studio 2013 Update 2

How to Use Caliburn.Micro.Logging

NuGet

The easiest way to use Caliburn.Micro.Logging is with NuGet with package id Caliburn.Micro.Logging. However, if you are using the pre-release version, make sure enable pre-release versions in NuGet. Here is the command for the Package Manager Console

For the more command line challenged or GUI enabled, use the Add Package Reference dialog.

Getting the Code

You can find the code for Caliburn.Micro.Logging on github at Caliburn.Micro.Logging

Configuring Your Code to use Caliburn.Micro.Logging

Once you have added the Caliburn.Micro.Logging NuGet package to your project, just modify the bootstrapper by adding a static constructor that sets the GetLog delegate. In this sample I show the DebugLogger, but it could also be NLogLogger. You can also do this in App.cs file.

static App()
{
	LogManager.GetLog = type => new DebugLogger(type);
}

Once that change is made, compile and run. That’s it. You will now see debug output from the Caliburn.Micro framework, and your own log statements.

Gotchas

In the spirit of no good deed goes unpunished, there are some issues with PCL that I ran across and you may as well. If your app is targeting .NET 4.5 or .NET 4.5.1, you wont hit these, so if that’s you – move along – nothing to see here. If you are using 4.5.2, then you will get the following error messages:

Don’t Panic! I am not sure why this happens, or what is going on in Visual Studio land to get me to this happy place only for .NET 4.5.2, but the solution is simple. You need to add a reference to System.Runtime. However, this is not listed in the normal assembly references list. I found it by going to C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.6. Once you add it, all just works. I am sure this is just growing pains related to Portable Class Libraries.

Summary

This is not the worlds biggest revision – especially given the really small code base, but it is a move in the right direction. The use of portable class libraries is major shift in the .NET world, and a welcome one. It would be nice if the vast majority of code is portable, and only a small portion of what is developed is platform specific. Seems like the holy grail of the development community. We shall see.

In the meantime, if you have suggestions, comments, or critiques, please add a comment below, add an issue to the issue tracker, or send me email using the blog comment form.

Related

comments powered by Disqus