Skip to content

Instantly share code, notes, and snippets.

@chrisobriensp
Created September 15, 2017 15:06
Show Gist options
  • Save chrisobriensp/b206bded5a3fd76380cacb4204677edb to your computer and use it in GitHub Desktop.
Save chrisobriensp/b206bded5a3fd76380cacb4204677edb to your computer and use it in GitHub Desktop.
Uses Azure App Insights to track site provisioning and applying a PnP template
XMLTemplateProvider provider = new XMLFileSystemTemplateProvider(TEMPLATE_FILE_PATH, string.Empty);
ProvisioningTemplate template = provider.GetTemplate(TEMPLATE_FILE);
stopwatch = System.Diagnostics.Stopwatch.StartNew();
try
{
rootWeb.ApplyProvisioningTemplate(template);
stopwatch.Stop();
var applyTemplateMetrics = new Dictionary<string, double> { { "processingTime", stopwatch.Elapsed.TotalMilliseconds } };
var applyTemplateProperties = new Dictionary<string, string> { { "siteCollectionUrl", NEW_SITE_URL }, { "templateID", template.Id } };
// track success..
telemetry.TrackEvent("TemplateApplied", applyTemplateProperties, applyTemplateMetrics);
}
catch (Exception e)
{
stopwatch.Stop();
// also send the exception message to App Insights in this case..
var errorMetrics = new Dictionary<string, double> { { "processingTime", stopwatch.Elapsed.TotalMilliseconds } };
var errorProperties = new Dictionary<string, string> { { "exception", e.Message }, { "siteCollectionUrl", NEW_SITE_URL }, { "templateID", template.Id } };
// track failure..
telemetry.TrackEvent("ErrorApplyingTemplate", errorProperties, errorMetrics);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment