TLDR: Add HttpTracer to your project and pass a new instance to HttpClient for Fiddler-like http audit/debug capabilities.
What is HttpTracer?
About a year ago, Daniel John Causer, Chase Florell and I decided that some code that I was using to inspect HTTP traffic in my Xamarin apps should be an open source library.
The code was simple enough, a simple DelegatingHandler that you can pass into your HttpClient instance and it would print your app’s http traffic to your debug output. The output would contain the method, url, headers and content for both requests and responses.
After working through issues with the initial implementation and the learning curve with releasing a library to the general public via nuget (this was a first for Daniel and me), we at last had a solid library that worked as advertised out of the box.
We were aware that the library wasn’t perfect and shipping it in a production app bordered on irresponsible. Logging all http traffic from your app is a heavy operation and a potential security risk. I decided to build out a feature that would fine grain control over what was captured and logged.
After some excellent suggestions from Allan Ritchie and Chase Florell, I built out the verbosity features and published a package to Myget. From there, I was able to test with several real apps to ensure that the library was functioning properly. I fixed my issues, republished, retested and pushed HttpTracer 2.0 on Nuget!
Working on this project has been an excellent learning experience. Owning and maintaining my first open source application has taught me many things about testing, designing libraries for public consumption, nuget packaging, multi-targeting and more.
We are now discussing some wishlist items, like being able to tie into some of the existing logger interfaces that are a part of .NET (currently you would need an adapter class).
I also took some time to try the framework with Blazor. It was a great learning experience as well, being able to work with .NET Core 3.0 for the first time and WASM too! After some stumbles, I was finally able to get HttpTracer working in a small Blazor app, it’s less useful in the context of WASM since you can just use the network tab in developer tools to inspect requests, but it’s still really cool to see the library working with a cutting edge platform!
I’m going to speak from experience here because it’s been a long road. The first 2 years I worked on Xamarin and mobile projects, I used a Windows machine, it was a decent laptop with an Intel Core i7 chip, 16 GB of ram and an SSD, not bad, right? Well, for any other task, yeah, it was perfect, but for Xamarin, it struggled. Loading solutions was slow and deploying/debugging with Android emulators was glacial. Debugging iOS was a huge pain; yes, Visual Studio has the ability to connect to a Mac build agent, but it’s unreliable, buggy and requires an exact version match. Too many moving parts.
I took the plunge about 2 years ago and began using a MacBook Pro full time and let me tell you, it has been a huge improvement. Visual Studio for Mac is fast and lightweight, you can run/debug iOS and Android on one piece of hardware and it’s really fast to deploy to the iOS Simulator. Switching provided a massive boost to my development productivity.
Furthermore, I didn’t even have to turn my back on Windows, I can dual boot with Bootcamp and run Windows inside a VM using Parallels. The best of both worlds!
With almost 3 years of full time macOS use behind me, here are my observations/recommendations to help ease the transition from Windows/PC to Mac.
macOS for Xamarin Developers
Hardware – I have a MacBook Pro (Retina, 15-inch, Mid 2015). I ordered this laptop in early 2016 when the newer models were announced. Looking at the benchmarks at the time, any performance benefits from the marginal CPU upgrade in the new models were far outweighed by the cons (lack of connectivity ports, no dedicated power port, bad keyboard). No regrets, this machine is a workhorse, decently fast, good battery life and handles a VM nicely.
Peripherals – In my home office, I use a DisplayLink USB 3.0 dual HD dock to drive twin 24″ 1920×1200 monitors that flank my laptop stand. This dock always worked wonderfully with my Windows machines, but was always a bit finnicky with my Mac and had much higher latency than plugging in the display directly. Since 10.13 “High Sierra” I have abandoned the display capabilities of the dock completely. High Sierra implemented changes which broke the dock’s capabilities. I now plug in both monitors, one to HDMI and one to mini DisplayPort. Frustrating to manage all the cords/connections, but the displays have lower latency with a direct connection.
Networking – macOS has no concept of a metered connection like Windows or Android. If you spend any amount of time using a portable hotspot/tethering/limited wifi, you will want to grab TripMode. If left unchecked, your Mac (and it’s applications) will treat all your connections like an unlimited, high-speed link which will cost you time and money.
Virtual Desktops – “Spaces” work relatively well. There tends to be a few bugs and hiccups, but they’re certainly handy.
Window Management – You’re going to miss Window’s snapping features more than you will ever know. Get a replacement, I recommend Magnet. Windows users will also need to get used to the fact that the “Maximize” doesn’t exist and the green button in the top left of the application title moves the application to a dedicated space/virtual desktop. You can split the screen in full screen spaces similar to snapping, but it’s restrictive and irritating.
Google Drive – the new Google Drive File Stream is generally ok. You will want to close it if you’re on a slow/unstable connection as it tends to start eating CPU.
Office – Microsoft’s Office for Mac is adequate for most tasks. Excel lacks a lot of the features necessary for manipulating large datasets and there is no Visio for Mac (try draw.io for basic diagrams). Outlook has been a trainwreck over the last few releases and I’ve taken to angrily tweeting about it:
The last few @Outlook for Mac updates have made me want to throw it away and find something better. Crashing/hanging/eating CPU+memory, switching from mail to calendar view fails often, can't drag calendar appointments (when I can get to calendar).
Using the tools and techniques described above can help your productivity on a Mac. Overall, the switch will be a bit rocky if you’re unfamiliar, in the end you will move much faster and ship your apps sooner by using a Mac!
More to come next time when we talk about IDEs and development tools.