When using the WP7Contrib packages from nuget.org you will be using the release build versions of the assemblies. Unfortunately what you won't get is the debug information generated by the services and other classes in the contrib. What is detailed below is steps you can use to get this debug information when using the packages.
I am aware NuGet now supports the publication of PDBs & symbols to symbolsource.org (more info can be found here). We haven't yet got round to factoring this into our publication process. When I say process, I mean when I use NuGet Package Explorer to do the publish to NuGet. I'm not sure the explorer currently supports this feature (hopefully I'm wrong). When this is done you'll be able to step through the contrib code base.
We also provide another way to get debug information at runtime via the ILog interface. The caching, communications & services namespaces make use of this interface. Like all dependencies in the contrib it can be injected in via the class constructor - all these classes provide overload constructors for this.
So the interface looks like this:
Before I show how I implement a local version of this to help debug an application, lets see how an example application using the Bing Maps Wrapper service (out of the box) doesn't produce any logging information.
So the following code makes a call out to Bings Maps API to get the location information for a post code (zip code). As you can see from the highlighted box the only output is the write line from the Rx subscriber when the result is returned.
Now this is great when the code has executed the 'happy path', but what happens if something goes wrong because of bad input data or there is a bug in the contrib? You're not going to see anything helpful coming out of the contrib apart from maybe a formatted exception.
This is where the ILog interface comes into play, if you have an implementation that uses the Debug.WriteLine() method you can quickly see what is going on under the covers.
Shown below is a class I drop into any solution using the NuGet versions of the contrib, you can get a copy here (DebugLog.cs):
You then have to wire this into the contrib classes that accept an instance of the ILog interface. Shown below is the re-worked example from above.
As you can see you get a lot of information in real-time about what's going on inside the contrib. In this case you can see the call out to the URL endpoint, the response headers returned, the deserialization time for the returned data and finally the result being added to the In Memory Cache Provider.
I hope this helps someone trying to use the contrib :).
Also, we don't currently use any AOP tools to weave in debug\trace information but this might well be added in the future, and we are going to improve our constructors for classes - to make these easier to use for people not working with DI frameworks.
I am aware NuGet now supports the publication of PDBs & symbols to symbolsource.org (more info can be found here). We haven't yet got round to factoring this into our publication process. When I say process, I mean when I use NuGet Package Explorer to do the publish to NuGet. I'm not sure the explorer currently supports this feature (hopefully I'm wrong). When this is done you'll be able to step through the contrib code base.
We also provide another way to get debug information at runtime via the ILog interface. The caching, communications & services namespaces make use of this interface. Like all dependencies in the contrib it can be injected in via the class constructor - all these classes provide overload constructors for this.
So the interface looks like this:
public interface ILog
{
ILog Write(string message);
ILog Write(string message, params object[] args);
ILog Write(string message, Exception exception);
ILog WriteDiagnostics();
}
Before I show how I implement a local version of this to help debug an application, lets see how an example application using the Bing Maps Wrapper service (out of the box) doesn't produce any logging information.
So the following code makes a call out to Bings Maps API to get the location information for a post code (zip code). As you can see from the highlighted box the only output is the write line from the Rx subscriber when the result is returned.
Now this is great when the code has executed the 'happy path', but what happens if something goes wrong because of bad input data or there is a bug in the contrib? You're not going to see anything helpful coming out of the contrib apart from maybe a formatted exception.
This is where the ILog interface comes into play, if you have an implementation that uses the Debug.WriteLine() method you can quickly see what is going on under the covers.
Shown below is a class I drop into any solution using the NuGet versions of the contrib, you can get a copy here (DebugLog.cs):
public sealed class DebugLog : ILog
{
private const string DateFormat = "dd-MM-yyyy HH:mm:ss.fff";
public ILog Write(string message)
{
Debug.WriteLine(string.Format("{0} - {1}", DateTime.Now.ToString(DateFormat), message));
return this;
}
public ILog Write(string message, params object[] args)
{
var messageWithParameters = string.Format(message, args);
Debug.WriteLine(string.Format("{0} - {1}", DateTime.Now.ToString(DateFormat), messageWithParameters));
return this;
}
public ILog Write(string message, Exception exception)
{
var date = DateTime.Now.ToString(DateFormat);
Debug.WriteLine(string.Format("{0} - {1}", date, message));
Debug.WriteLine((string.Format("{0} - Exception '{1}'", date, exception)));
return this;
}
public ILog WriteDiagnostics()
{
return this;
}
}
You then have to wire this into the contrib classes that accept an instance of the ILog interface. Shown below is the re-worked example from above.
As you can see you get a lot of information in real-time about what's going on inside the contrib. In this case you can see the call out to the URL endpoint, the response headers returned, the deserialization time for the returned data and finally the result being added to the In Memory Cache Provider.
I hope this helps someone trying to use the contrib :).
Also, we don't currently use any AOP tools to weave in debug\trace information but this might well be added in the future, and we are going to improve our constructors for classes - to make these easier to use for people not working with DI frameworks.
Comments
Post a Comment