Logging errors with MonoDroid and Android
Error logging, its such a simple concept. When an error occurs, store some kind of information about the error. For some reason, we don't seem to do lots of it. Why? Well, its usually fairly easy to track down the information about an exception. With most web apps, you can pretty much repeat the errors as you need to. Logging on the server is fairly easy. Networks are fairly high speed and dependable items of infrastructure. Is error logging really that necessary?
Yes Virginia, error logging really is important. In the mobile world, networks are not high speed or dependable. How do you store information about those errors when the user is disconnected? You can't just automagically write errors to the server log. What if errors are occurring due to a bad network connection? How do I store errors in a standard way? Well, I can't help you with everything, but I can help you with storing errors on an Android Device with MonoDroid.
Storing error information with MonoDroid is actually fairly easy. Android contains a set of Log.* methods to store data. So, my strategy is basically a multi-step approach:
-
Store application information in Android with Android.Util.Log.* methods. With these methods, you are writing to the standard Android log. This will store errors in the standard locations in android. Note that these are different from the MonoTouch methods for storing errors. The MonoTouch method for this is Console.WriteLine.
-
If I am going to log errors in a running application that will be released into the wild, storing the errors for future removal is important. This can be stored in a SqLite database table on the device.
-
Getting information from the device. To properly get information from the device, we'll need to store this in a remote database for further analysis. There needs to be a web service, preferably a REST based service, for the device to communicate to and a database that holds the data.
Hopefully, this helps you out with your data logging ideas.
Wally