public void Execute(IServiceProvider serviceProvider)
        {
            //https://msdn.microsoft.com/en-us/library/gg509027.aspx
            //When you use the Update method or UpdateRequest message, do not set the OwnerId attribute on a record unless the owner has actually changed.
            //When you set this attribute, the changes often cascade to related entities, which increases the time that is required for the update operation.
            //Extract the tracing service for use in debugging sandboxed plug-ins.
            ITracingService tracingService =
                (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            tracingService.Trace("Starting SendApplicationInsights at " + DateTime.Now.ToString());
            // Obtain the execution context from the service provider.
            IPluginExecutionContext context = (IPluginExecutionContext)
                                              serviceProvider.GetService(typeof(IPluginExecutionContext));

            Microsoft.Xrm.Sdk.PluginTelemetry.ILogger logger = (Microsoft.Xrm.Sdk.PluginTelemetry.ILogger)
                                                               serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.PluginTelemetry.ILogger));
            XmlDocument doc           = new XmlDocument();
            DateTime    executionTime = DateTime.Now.ToUniversalTime();

            tracingService.Trace("Parse and Search Unsecure Config at " + DateTime.Now.ToString());
            doc.LoadXml(_unsecureString);
            _instrumentationKey = GetValueNode(doc, "instrumentationKey");
            PostBody postBody = new PostBody()
            {
                iKey = _instrumentationKey
            };

            try {
                logger.IsEnabled(Microsoft.Xrm.Sdk.PluginTelemetry.LogLevel.Information);
                logger.LogInformation("test from ILogger");
                logger.LogTrace("Log Trace");
                logger.LogWarning("Log Trace");
                //logger.LogMetric("testMetric", new long());
                logger.LogError("Log Trace");
                logger.LogCritical("Log Trace");
                tracingService.Trace("Create Custom Event Data DTO at " + DateTime.Now.ToString());
                postBody.data.baseData = Events.CreateCustomEventData(postBody.data.baseData, context);
                postBody.data.baseData.properties.Add("ExecutionTime", executionTime.ToString());
                tracingService.Trace("Send Custom Event Request at " + DateTime.Now.ToString());
                PushMessageToApplicationInsights messenger = new PushMessageToApplicationInsights();
                messenger.SendRequest(postBody, tracingService, logger);
            }
            catch (InvalidPluginExecutionException ex) {
                postBody.data.baseData = Exceptions.CreateExceptionEventData(postBody.data.baseData, ex, context);
                PushMessageToApplicationInsights messenger = new PushMessageToApplicationInsights();
                messenger.SendRequest(postBody, tracingService, logger);
                throw new InvalidPluginExecutionException(ex.Message);
            }
        }
        public void Execute(IServiceProvider serviceProvider)
        {
            //https://msdn.microsoft.com/en-us/library/gg509027.aspx
            //When you use the Update method or UpdateRequest message, do not set the OwnerId attribute on a record unless the owner has actually changed.
            //When you set this attribute, the changes often cascade to related entities, which increases the time that is required for the update operation.
            //Extract the tracing service for use in debugging sandboxed plug-ins.
            ILogger         logger         = (ILogger)serviceProvider.GetService(typeof(ILogger));
            ITracingService tracingService =
                (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            tracingService.Trace("Starting SendApplicationInsights at " + DateTime.Now.ToString());
            // Obtain the execution context from the service provider.
            IPluginExecutionContext context = (IPluginExecutionContext)
                                              serviceProvider.GetService(typeof(IPluginExecutionContext));
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(_unsecureString);
            tracingService.Trace("Loaded Unsecure Configuration XML " + DateTime.Now.ToString());
            _instrumentationKey = GetValueNode(doc, "instrumentationKey");
            try {
                PostBody postBody = new PostBody();
                postBody.iKey = _instrumentationKey;
                tracingService.Trace("Created PostBody with iKey = " + postBody.iKey + " " + DateTime.Now.ToString());
                try {
                    throw new InvalidPluginExecutionException("Test Exception");
                }
                catch (InvalidPluginExecutionException e) {
                    postBody.data.baseData = Exceptions.CreateExceptionEventData(postBody.data.baseData, e, context);
                    tracingService.Trace("Set baseData for Exception Request " + DateTime.Now.ToString());
                    PushMessageToApplicationInsights messenger = new PushMessageToApplicationInsights();
                    messenger.SendRequest(postBody, tracingService, logger);
                    tracingService.Trace("Sent Request " + DateTime.Now.ToString());
                    throw e;
                }
            }
            catch (Exception ex) {
                tracingService.Trace("Caught final exception " + DateTime.Now.ToString());
                throw new InvalidPluginExecutionException(ex.Message);
            }
        }