Created
September 15, 2017 15:06
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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