This is the time of the year, that we celebrate the Xamarin Month and the community through the efforts of Luis Matos agreed to share code snippets that will make Xamarin Developers more productive and efficient by fully utilizing the code snippets feature of Visual Studio. With that in mind, I would like to share with you some simple code snippets that I used when integrating App Center analytics for Xamarin.
Configuration of Code Snippet Manager
In order to use custom code snippet first you need to download the “.snippet” file from this link as seen in Figure 1.

After downloading the said files, we can add them in you Visual Studio by under the “Tools -> Code Snippet Manager” menu as show in Figure 2.

After clicking the Code Snippet Manager, you should see a “Menu” like in Figure 3.

Let’s try to upload the code snippets by clicking the “Import button” then select all the .snippet files and click open as show in Figure 4.

After selecting the files to be uploaded, you will be asked on the location of the snippets to be organized which should be under “My Code Snippet” and just click the finish button as shown in Figure 5.

To verify if you have successfully added the .snippets you need to go to specific programming language which is C# as shown in Figure 6.

App Center Start
The first code snippet that I would like to share is the initialization or starting of the App Center analytics. Keep in mind that this is only code snippets so this will not automatically download and install the NuGet package needed so that you can use App Center analytics. The good thing for the code App Center analytics code snippets that I have is that it will automatically add the namespace needed for the corresponding code snippet. The expected command is “as” (AppCenter Start) and just click double tab to execute the shortcut command as seen in Figure 7.

App Center Tracking of Simple Events
The second code snippet that I would like to share is the simple tracking of Events in App Center. The expected command is “ates” (AppCenter Track Events Simple) and just click double tab to execute the shortcut command as seen in Figure 8. You can use this shortcut if you just want a straight forward tracking of events.

App Center Tracing of Full Events
We have already seen the simple tracking of events, what if you needed more details like app version and information. So the third code snippet that I would like to share is the full tracking of Events in App Center in which you can add information like date, app version, app id and details of the event so that you can thoroughly log events. The expected command is “atef” (AppCenter Track Events Full) and just click double tab to execute the shortcut command as seen in Figure 9.

App Center Tracing of Crashes
The final snippet that I would like to share is the tracking of crashes in App Center. If you have not set you app center analytics to automatically send logs whenever there are app crash that have been encountered you can use this app center crash tracking instead in your try catch statements. The expected command is “atc” (AppCenter Track Crashes) and just click double tab to execute the shortcut command as seen in Figure 10.

Conclusion
To wrap things up, we discussed on how to simply integrate .snippet files in Visual Studio. I’ve also shared simple App Center code snippets that will prove useful especially on debugging application events as well as app crashes in you Xamarin Application. Hope you’ll try to use my code snippets in your daily Xamarin development as well as inspire you to create your own code snippets. Again a big kudos for Luis Matos for setting up the Xamarin Month Celebration and kindly also check the awesome code snippets from the other cool Xamarin developers that have contributed during this Xamarin month celebration in this link.
Happy Coding 🙂