/// <summary> /// Notifies this extension component that it has been registered in the owner's collection of extensions. /// </summary> /// <param name="owner">The extensible owner object that aggregates this extension.</param> public void Attach(IExtensibleCloudServiceComponent owner) { owner.Extensions.Demand <IRoleConfigurationSettingsExtension>(); this.roleConfigExtension = owner.Extensions.Find <IRoleConfigurationSettingsExtension>(); this.communicationRetryPolicy = this.roleConfigExtension.CommunicationRetryPolicy; }
/// <summary> /// Starts the service hosts that are declaratively attached to the hosting worker role and the AutoStart attribute of which matches the specified value. /// </summary> /// <param name="autoStartOnly">A flag indicating whether to start only those service hosts that are marked with the AutoStart attribute.</param> public void StartAll(bool autoStartOnly) { var callToken = TraceManager.WorkerRoleComponent.TraceIn(autoStartOnly); var startScopeOpenServiceHosts = TraceManager.WorkerRoleComponent.TraceStartScope(TraceLogMessages.ScopeOpenServiceHosts, callToken); if (this.workerRole != null) { IRoleConfigurationSettingsExtension roleConfigExtension = this.workerRole.Extensions.Find <IRoleConfigurationSettingsExtension>(); if (roleConfigExtension != null) { foreach (var ep in serviceEndpoints.Values) { if (null == ep.ServiceHost) { TraceManager.WorkerRoleComponent.TraceInfo(TraceLogMessages.AboutToCreateServiceHost, ep.ServiceType.FullName, ep.EndpointInfo.Name, ep.EndpointInfo.ServiceNamespace, ep.EndpointInfo.ServicePath, ep.EndpointInfo.EndpointType); ep.ServiceHost = new ReliableServiceBusHost <object>(ServiceBusHostFactory.CreateServiceBusHost(ep.EndpointInfo, ep.ServiceType), roleConfigExtension.CommunicationRetryPolicy); } if (ep.ServiceHost != null && ep.ServiceHost.State != CommunicationState.Opened && (!autoStartOnly || ep.AutoStart)) { ep.ServiceHost.Open(); } } } } else { throw new CloudApplicationException(String.Format(CultureInfo.CurrentCulture, ExceptionMessages.CloudRoleExtensionNotAttached, this.GetType().Name)); } TraceManager.WorkerRoleComponent.TraceEndScope(TraceLogMessages.ScopeOpenServiceHosts, startScopeOpenServiceHosts, callToken); TraceManager.WorkerRoleComponent.TraceOut(callToken); }
/// <summary> /// Notifies this extension component that it has been registered in the owner's collection of extensions. /// </summary> /// <param name="owner">The extensible owner object that aggregates this extension.</param> public void Attach(IExtensibleCloudServiceComponent owner) { owner.Extensions.Demand <IRoleConfigurationSettingsExtension>(); IRoleConfigurationSettingsExtension roleConfigExtension = owner.Extensions.Find <IRoleConfigurationSettingsExtension>(); this.settings = new WorkItemProcessorConfigurationSettings(roleConfigExtension.GetSection <ApplicationConfigurationSettings>(WorkItemProcessorConfigurationSettings.SectionName)); }
/// <summary> /// Notifies this extension component that it has been registered in the owner's collection of extensions. /// </summary> /// <param name="owner">The extensible owner object that aggregates this extension.</param> public void Attach(IExtensibleCloudServiceComponent owner) { IRoleConfigurationSettingsExtension roleConfigExtension = owner.Extensions.Find <IRoleConfigurationSettingsExtension>(); if (roleConfigExtension != null) { this.activityTrackingClient = new ReliableServiceBusClient <IActivityTrackingServiceChannel>(roleConfigExtension.OnPremiseRelayOneWayEndpoint, roleConfigExtension.CommunicationRetryPolicy); } }
private void ConfigureDefaults() { IRoleConfigurationSettingsExtension roleConfigExtension = Extensions.Find <IRoleConfigurationSettingsExtension>(); ApplicationDiagnosticSettings diagnosticSettings = roleConfigExtension.GetSection <ApplicationDiagnosticSettings>(ApplicationDiagnosticSettings.SectionName); // If heartbeat interval is defined in the application diagnostic settings, override the default interval for this role. if (diagnosticSettings != null && diagnosticSettings.HeartbeatInterval.TotalMilliseconds > 0) { HeartbeatInterval = diagnosticSettings.HeartbeatInterval; } }
/// <summary> /// Notifies this extension component that it has been registered in the owner's collection of extensions. /// </summary> /// <param name="owner">The extensible owner object that aggregates this extension.</param> public void Attach(IExtensibleCloudServiceComponent owner) { owner.Extensions.Demand <IWorkItemProcessorConfigurationExtension>(); owner.Extensions.Demand <IRoleConfigurationSettingsExtension>(); owner.Extensions.Demand <ICloudCacheProviderExtension>(); owner.Extensions.Demand <IRulesEngineServiceClientExtension>(); this.configSettingsExtension = owner.Extensions.Find <IWorkItemProcessorConfigurationExtension>(); this.roleConfigExtension = owner.Extensions.Find <IRoleConfigurationSettingsExtension>(); this.cacheProviderExtension = owner.Extensions.Find <ICloudCacheProviderExtension>(); this.rulesEngineExtension = owner.Extensions.Find <IRulesEngineServiceClientExtension>(); }
private void SubmitApplication(LoanApplicationData loanApp) { LoanApplicationProcess loanRequestActivity = new LoanApplicationProcess(loanApp.ApplicationID) { ApplicantID = loanApp.Ssn, LoanApplicationSubmitted = DateTime.UtcNow }; // Ensure the availability of required extensions, throw an exception if not available. Global.WebRoleSingleton.Extensions.Demand <IActivityTrackingEventStreamExtension>(); Global.WebRoleSingleton.Extensions.Demand <IRulesEngineServiceClientExtension>(); IActivityTrackingEventStreamExtension trackingEventStream = Global.WebRoleSingleton.Extensions.Find <IActivityTrackingEventStreamExtension>(); IRulesEngineServiceClientExtension ruleEngineClient = Global.WebRoleSingleton.Extensions.Find <IRulesEngineServiceClientExtension>(); IRoleConfigurationSettingsExtension roleConfig = Global.WebRoleSingleton.Extensions.Find <IRoleConfigurationSettingsExtension>(); // Tells the event stream to invoke the BeginActivity operation. trackingEventStream.BeginActivity(loanRequestActivity); // Call BRE rule to obtain a pre-approval. SimpleValueFact result = ruleEngineClient.ExecutePolicy <SimpleValueFact>("Contoso.Cloud.Integration.Demo.LoanPreapproval", loanApp); // Update the LoanPreapprovalReceived milestone. loanRequestActivity.LoanPreapprovalDecision = Convert.ToString(result.Value); loanRequestActivity.LoanPreapprovalReceived = DateTime.UtcNow; // Display pre-approval decision. SetResultDisplay(loanRequestActivity.LoanPreapprovalDecision); // Tells the event stream to invoke the UpdateActivity. trackingEventStream.UpdateActivity(loanRequestActivity); // Submit pre-approved loan for final processing. if (String.Compare(loanRequestActivity.LoanPreapprovalDecision, "Preapproved", true) == 0) { // Submit the loan application for processing (this will update LoanApplicationStarted, LoanFinalDecision and LoanFinalDecisionMade milestones. using (var loanProcessor = new ReliableServiceBusClient <ILoanApplicationProcessingServiceChannel>(roleConfig.GetServiceBusEndpoint("LoanApplication"), roleConfig.CommunicationRetryPolicy)) { loanProcessor.RetryPolicy.ExecuteAction(() => { loanProcessor.Client.Submit(loanApp); }); } } // Update the LoanFinalDecisionReceived milestone. loanRequestActivity.LoanFinalDecisionReceived = DateTime.UtcNow; // Tells the event stream to invoke the UpdateActivity and EndActivity operations. trackingEventStream.CompleteActivity(loanRequestActivity); }
private void ConfigureServiceHostWorkerRole(IExtensibleCloudServiceComponent ownerRole) { var callToken = TraceManager.WorkerRoleComponent.TraceIn(ownerRole != null ? ownerRole.GetType().FullName : null); var startScopeCreateServiceHosts = TraceManager.WorkerRoleComponent.TraceStartScope(TraceLogMessages.ScopeCreateServiceHosts, callToken); if (ownerRole != null) { IList <ServiceBusHostWorkerRoleAttribute> serviceHostAttributes = FrameworkUtility.GetDeclarativeAttributes <ServiceBusHostWorkerRoleAttribute>(ownerRole.GetType()); IRoleConfigurationSettingsExtension roleConfigExtension = ownerRole.Extensions.Find <IRoleConfigurationSettingsExtension>(); if (serviceHostAttributes != null && serviceHostAttributes.Count > 0 && roleConfigExtension != null) { ServiceBusEndpointInfo endpointInfo = null; ServiceBusListenerRegistration listenerInfo = null; foreach (ServiceBusHostWorkerRoleAttribute serviceHostAttr in serviceHostAttributes) { endpointInfo = roleConfigExtension.GetServiceBusEndpoint(serviceHostAttr.ServiceBusEndpoint); if (endpointInfo != null) { listenerInfo = new ServiceBusListenerRegistration() { ServiceType = serviceHostAttr.ServiceType, EndpointInfo = endpointInfo, AutoStart = serviceHostAttr.AutoStart }; // All services that are enabled for auto-start will have their service hosts pre-initialized but not as yet openned. if (listenerInfo.AutoStart) { TraceManager.WorkerRoleComponent.TraceInfo(TraceLogMessages.AboutToCreateServiceHost, listenerInfo.ServiceType.FullName, endpointInfo.Name, endpointInfo.ServiceNamespace, endpointInfo.ServicePath, endpointInfo.EndpointType); listenerInfo.ServiceHost = new ReliableServiceBusHost <object>(ServiceBusHostFactory.CreateServiceBusHost(endpointInfo, listenerInfo.ServiceType), roleConfigExtension.CommunicationRetryPolicy); } this.serviceEndpoints.Add(endpointInfo, listenerInfo); } else { throw new CloudApplicationException(String.Format(CultureInfo.CurrentCulture, ExceptionMessages.SpecifiedServiceBusEndpointNotFound, serviceHostAttr.ServiceBusEndpoint, ServiceBusConfigurationSettings.SectionName)); } } } } TraceManager.WorkerRoleComponent.TraceEndScope(TraceLogMessages.ScopeCreateServiceHosts, startScopeCreateServiceHosts, callToken); TraceManager.WorkerRoleComponent.TraceOut(callToken); }
/// <summary> /// Extends the OnStart phase that is called by Windows Azure runtime to initialize the role instance. /// </summary> /// <returns>True if initialization succeeds, otherwise false.</returns> protected override bool OnRoleStart() { this.EnsureExists <ScalableTransformConfigurationExtension>(); this.EnsureExists <CloudStorageProviderExtension>(); this.EnsureExists <XslTransformMetadataProviderExtension>(); this.EnsureExists <XslTransformInProcCacheExtension>(); this.EnsureExists <XslTransformProviderExtension>(); this.EnsureExists <EndpointConfigurationDiscoveryExtension>(); IEndpointConfigurationDiscoveryExtension discoveryExtension = Extensions.Find <IEndpointConfigurationDiscoveryExtension>(); IRoleConfigurationSettingsExtension roleConfigExtension = Extensions.Find <IRoleConfigurationSettingsExtension>(); IScalableTransformConfigurationExtension serviceConfigExtension = Extensions.Find <IScalableTransformConfigurationExtension>(); StorageAccountConfigurationSettings storageSettings = roleConfigExtension.GetSection <StorageAccountConfigurationSettings>(StorageAccountConfigurationSettings.SectionName); XslTransformCloudBlobCacheExtension cloudBlobCache = new XslTransformCloudBlobCacheExtension(storageSettings.Accounts.Get(serviceConfigExtension.Settings.CacheStorageAccount)); CloudStorageLoadBalancingExtension storageLoadBalancer = new CloudStorageLoadBalancingExtension(from name in serviceConfigExtension.Settings.StorageAccounts.AllKeys select storageSettings.Accounts.Get(name)); // Configure the cache TTL for the blob caching extension. cloudBlobCache.CacheTimeToLive = serviceConfigExtension.Settings.BlobCacheTimeToLive; // Configure the cache TTL for the in-proc caching extension. XslTransformInProcCacheExtension memoryCache = Extensions.Find <XslTransformInProcCacheExtension>(); memoryCache.CacheTimeToLive = serviceConfigExtension.Settings.MemoryCacheTimeToLive; Extensions.Add(cloudBlobCache); Extensions.Add(storageLoadBalancer); // Done with configuring all infrastructure extensions, now proceed with registering the service extension that implements the core methods. this.EnsureExists <ScalableTransformServiceExtension>(); var contractTypeMatchCondition = ServiceEndpointDiscoveryCondition.ContractTypeExactMatch(typeof(IScalableTransformationServiceContract)); var bindingTypeMatchCondition = ServiceEndpointDiscoveryCondition.BindingTypeExactMatch(typeof(NetTcpRelayBinding)); discoveryExtension.RegisterDiscoveryAction(new[] { contractTypeMatchCondition, bindingTypeMatchCondition }, (endpoint) => { NetTcpRelayBinding relayBinding = endpoint.Binding as NetTcpRelayBinding; if (relayBinding != null) { relayBinding.TransferMode = TransferMode.Streamed; } }); return(true); }
/// <summary> /// Notifies this extension component that it has been registered in the owner's collection of extensions. /// </summary> /// <param name="owner">The extensible owner object that aggregates this extension.</param> public void Attach(IExtensibleCloudServiceComponent owner) { owner.Extensions.Demand <IRoleConfigurationSettingsExtension>(); IRoleConfigurationSettingsExtension roleConfigExtension = owner.Extensions.Find <IRoleConfigurationSettingsExtension>(); this.serviceBusEndpoint = roleConfigExtension.GetServiceBusEndpoint(WellKnownEndpointName.InterRoleCommunication); this.retryPolicy = roleConfigExtension.CommunicationRetryPolicy; if (this.serviceBusEndpoint != null) { // Configure Service Bus credentials and entity URI. var credentials = TransportClientCredentialBase.CreateSharedSecretCredential(this.serviceBusEndpoint.IssuerName, this.serviceBusEndpoint.IssuerSecret); var address = ServiceBusEnvironment.CreateServiceUri(WellKnownProtocolScheme.ServiceBus, this.serviceBusEndpoint.ServiceNamespace, String.Empty); // Configure Service Bus messaging factory and namespace client which is required for subscription management. this.messagingFactory = MessagingFactory.Create(address, credentials); this.managementClient = new ServiceBusNamespaceClient(address, credentials); ConfigureTopicClient(); ConfigureSubscriptionClient(this.ircSubscription = ConfigureSubscription(String.Concat(SubscriptionNamePrefix, this.senderInstanceID))); // Configure event receive action. this.receiveAction = (() => { BrokeredMessage msg = null; this.retryPolicy.ExecuteAction(() => { // Make sure we are not told to stop receiving while we are retrying. if (!cts.IsCancellationRequested) { if (EventReceiver.TryReceive(Settings.EventWaitTimeout, out msg)) { try { // Make sure we are not told to stop receiving while we were waiting for a new message. if (!cts.IsCancellationRequested) { // Extract the event data from brokered message. InterRoleCommunicationEvent e = msg.GetBody <InterRoleCommunicationEvent>(); // Notify all registered subscribers. NotifySubscribers(e); // Mark brokered message as complete. msg.Complete(this.retryPolicy); } else { msg.Defer(this.retryPolicy); } } catch (Exception ex) { // Abandons a brokered message and unlocks the message. msg.Abandon(this.retryPolicy); // Log an error. TraceManager.ServiceComponent.TraceError(ex); } } } }); }); // Configure event receive complete action. this.endReceive = ((ar) => { this.receiveAction.EndInvoke(ar); if (!cts.IsCancellationRequested) { this.receiveHandle = this.receiveAction.BeginInvoke(this.endReceive, null); } }); // Configure event send action. this.sendAction = ((e) => { this.retryPolicy.ExecuteAction(() => { EventSender.Send(e); }); }); // Configure event send complete action. this.endSend = ((ar) => { sendAction.EndInvoke(ar); }); } else { throw new CloudApplicationException(String.Format(CultureInfo.CurrentCulture, ExceptionMessages.SpecifiedServiceBusEndpointNotFound, WellKnownEndpointName.InterRoleCommunication, ServiceBusConfigurationSettings.SectionName)); } }
private void HandlePersistenceQueueItem(PersistenceQueueItemInfo itemInfo) { Guard.ArgumentNotNull(itemInfo, "itemInfo"); this.owner.Extensions.Demand <IRulesEngineServiceClientExtension>(); this.owner.Extensions.Demand <IWorkItemSchedulerConfigurationExtension>(); this.owner.Extensions.Demand <IRoleConfigurationSettingsExtension>(); this.owner.Extensions.Demand <ICloudStorageProviderExtension>(); this.owner.Extensions.Demand <IInterRoleCommunicationExtension>(); IRulesEngineServiceClientExtension rulesEngineExtension = this.owner.Extensions.Find <IRulesEngineServiceClientExtension>(); IWorkItemSchedulerConfigurationExtension configSettingsExtension = this.owner.Extensions.Find <IWorkItemSchedulerConfigurationExtension>(); IRoleConfigurationSettingsExtension roleConfigExtension = this.owner.Extensions.Find <IRoleConfigurationSettingsExtension>(); ICloudStorageProviderExtension storageProviderExtension = this.owner.Extensions.Find <ICloudStorageProviderExtension>(); IActivityTrackingEventStreamExtension trackingEventStreamExtension = this.owner.Extensions.Find <IActivityTrackingEventStreamExtension>(); IInterRoleCommunicationExtension interCommExtension = this.owner.Extensions.Find <IInterRoleCommunicationExtension>(); // Update BAM activity to indicate when we started the dequeue operation. if (trackingEventStreamExtension != null) { InventoryDataTrackingActivity activity = new InventoryDataTrackingActivity(itemInfo.QueueItemId.ToString()) { DequeueOperationStarted = DateTime.UtcNow }; trackingEventStreamExtension.UpdateActivity(activity); } var xPathLib = roleConfigExtension.GetSection <XPathQueryLibrary>(XPathQueryLibrary.SectionName); var batchInfo = rulesEngineExtension.ExecutePolicy <PersistenceQueueItemBatchInfo>(configSettingsExtension.Settings.HandlingPolicyName, itemInfo, new MessageTypeFact(itemInfo.QueueItemType)); // Verify the batch metadata to ensure we have everything we need to be able to perform de-batching. ValidateBatchMetadata(itemInfo, batchInfo); // Replace the XPath query references with actual expressions taken from the XPath Library. batchInfo.BodyItemXPath = xPathLib.Queries.Contains(batchInfo.BodyItemXPath) ? xPathLib.GetXPathQuery(batchInfo.BodyItemXPath) : batchInfo.BodyItemXPath; batchInfo.BodyItemCountXPath = xPathLib.Queries.Contains(batchInfo.BodyItemCountXPath) ? xPathLib.GetXPathQuery(batchInfo.BodyItemCountXPath) : batchInfo.BodyItemCountXPath; var headerXPathList = from item in batchInfo.HeaderSegments where xPathLib.Queries.Contains(item) select new { Segment = item, XPath = xPathLib.GetXPathQuery(item) }; var bodyXPathList = from item in batchInfo.BodySegments where xPathLib.Queries.Contains(item) select new { Segment = item, XPath = xPathLib.GetXPathQuery(item) }; var footerXPathList = from item in batchInfo.FooterSegments where xPathLib.Queries.Contains(item) select new { Segment = item, XPath = xPathLib.GetXPathQuery(item) }; foreach (var item in headerXPathList.ToList()) { batchInfo.HeaderSegments.Remove(item.Segment); batchInfo.HeaderSegments.Add(item.XPath); } foreach (var item in bodyXPathList.ToList()) { batchInfo.BodySegments.Remove(item.Segment); batchInfo.BodySegments.Add(item.XPath); } foreach (var item in footerXPathList.ToList()) { batchInfo.FooterSegments.Remove(item.Segment); batchInfo.FooterSegments.Add(item.XPath); } int fromItem = 1, toItem = fromItem, maxItems = configSettingsExtension.Settings.XmlBatchSize; var taskParameters = new List <DequeueXmlDataTaskState>(); using (SqlAzurePersistenceQueue persistenceQueue = new SqlAzurePersistenceQueue()) { persistenceQueue.Open(WellKnownDatabaseName.PersistenceQueue); using (XmlReader resultReader = persistenceQueue.QueryXmlData(itemInfo.QueueItemId, new string[] { batchInfo.BodyItemCountXPath }, xPathLib.Namespaces.NamespaceManager)) { maxItems = resultReader.ReadContentAsInt(); } } do { toItem = fromItem + configSettingsExtension.Settings.XmlBatchSize - 1; taskParameters.Add(new DequeueXmlDataTaskState() { QueueItemInfo = itemInfo, HeaderSegments = new List <string>(batchInfo.HeaderSegments), BodySegments = new List <string>(from query in batchInfo.BodySegments select String.Format(query, fromItem, toItem)), FooterSegments = new List <string>(batchInfo.FooterSegments), StartItemIndex = fromItem, EndItemIndex = toItem, ItemDetectionXPath = batchInfo.BodyItemXPath, Settings = configSettingsExtension.Settings, StorageProvider = storageProviderExtension, NamespaceManager = xPathLib.Namespaces.NamespaceManager }); fromItem += configSettingsExtension.Settings.XmlBatchSize; }while (toItem < maxItems); // Before we start putting work items on queue, notify the respective queue listeners that they should expect work to arrive. CloudQueueWorkDetectedTriggerEvent trigger = new CloudQueueWorkDetectedTriggerEvent(configSettingsExtension.Settings.CloudStorageAccount, configSettingsExtension.Settings.DestinationQueue, maxItems, PayloadSizeKind.MessageCount); // Package the trigger into an inter-role communication event. var interRoleEvent = new InterRoleCommunicationEvent(trigger); // Publish inter-role communication event via the Service Bus one-way multicast. interCommExtension.Publish(interRoleEvent); var stateCollection = from x in taskParameters.AsParallel <DequeueXmlDataTaskState>() orderby x.StartItemIndex select x; foreach (var state in stateCollection) { try { DequeueXmlDataTaskMain(state); } catch (Exception ex) { TraceManager.WorkerRoleComponent.TraceError(ex); } } // Update BAM activity to indicate when we completed the dequeue operation. if (trackingEventStreamExtension != null) { InventoryDataTrackingActivity activity = new InventoryDataTrackingActivity(itemInfo.QueueItemId.ToString()) { DequeueOperationCompleted = DateTime.UtcNow }; trackingEventStreamExtension.UpdateActivity(activity); } }
/// <summary> /// Notifies this extension component that it has been registered in the owner's collection of extensions. /// </summary> /// <param name="owner">The extensible owner object that aggregates this extension.</param> public void Attach(IExtensibleCloudServiceComponent owner) { IRoleConfigurationSettingsExtension roleConfigExtension = owner.Extensions.Find <IRoleConfigurationSettingsExtension>(); if (roleConfigExtension != null && CloudEnvironment.IsAvailable) { ApplicationDiagnosticSettings diagnosticSettings = roleConfigExtension.GetSection <ApplicationDiagnosticSettings>(ApplicationDiagnosticSettings.SectionName); StorageAccountConfigurationSettings storageSettings = roleConfigExtension.GetSection <StorageAccountConfigurationSettings>(StorageAccountConfigurationSettings.SectionName); if (diagnosticSettings != null) { if (diagnosticSettings.DiagnosticEnabled) { DiagnosticMonitorConfiguration diagnosticConfig = DiagnosticMonitor.GetDefaultInitialConfiguration(); // Configure the scheduled transfer period for all logs. diagnosticConfig.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = diagnosticSettings.DiagnosticLogsTransferPeriod.Coalesce(diagnosticSettings.DefaultTransferPeriod); diagnosticConfig.Directories.ScheduledTransferPeriod = diagnosticSettings.FileLogsTransferPeriod.Coalesce(diagnosticSettings.DefaultTransferPeriod); diagnosticConfig.Logs.ScheduledTransferPeriod = diagnosticSettings.TraceLogsTransferPeriod.Coalesce(diagnosticSettings.DefaultTransferPeriod); diagnosticConfig.PerformanceCounters.ScheduledTransferPeriod = diagnosticSettings.PerformanceCountersTransferPeriod.Coalesce(diagnosticSettings.DefaultTransferPeriod); diagnosticConfig.WindowsEventLog.ScheduledTransferPeriod = diagnosticSettings.EventLogsTransferPeriod.Coalesce(diagnosticSettings.DefaultTransferPeriod); // Configure the logs levels for scheduled transfers. diagnosticConfig.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = FromTraceSourceLevel(diagnosticSettings.DiagnosticLogsTransferFilter); diagnosticConfig.Logs.ScheduledTransferLogLevelFilter = FromTraceSourceLevel(diagnosticSettings.TraceLogsTransferFilter); diagnosticConfig.WindowsEventLog.ScheduledTransferLogLevelFilter = FromTraceSourceLevel(diagnosticSettings.EventLogsTransferFilter); // Configure the Windows Event Log data sources. foreach (string logName in diagnosticSettings.EventLogDataSources.AllKeys) { diagnosticConfig.WindowsEventLog.DataSources.Add(logName); } // Configure the data sources for file-based logs. foreach (string containerName in diagnosticSettings.FileLogDirectories.AllKeys) { diagnosticConfig.Directories.DataSources.Add(new DirectoryConfiguration() { Container = containerName, Path = diagnosticSettings.FileLogDirectories[containerName].Value }); } // Configure the data sources for performance counter data foreach (string counterName in diagnosticSettings.PerformanceCountersDataSources.AllKeys) { diagnosticConfig.PerformanceCounters.DataSources.Add(new PerformanceCounterConfiguration() { CounterSpecifier = counterName, SampleRate = TimeSpan.Parse(diagnosticSettings.PerformanceCountersDataSources[counterName].Value) }); } // Configure crash dumps collection. if (diagnosticSettings.CrashDumpCollectionEnabled) { CrashDumps.EnableCollection(true); } // Look up for the storage account definition. StorageAccountInfo storageAccountInfo = storageSettings.Accounts.Get(diagnosticSettings.DiagnosticStorageAccount); if (storageAccountInfo != null) { CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentialsAccountAndKey(storageAccountInfo.AccountName, storageAccountInfo.AccountKey), true); RetryPolicy retryPolicy = roleConfigExtension.StorageRetryPolicy; // Start the Azure Diagnostic Monitor using a retryable scope. this.diagnosticMonitor = retryPolicy.ExecuteAction <DiagnosticMonitor>(() => { return(DiagnosticMonitor.Start(storageAccount, diagnosticConfig)); }); } } else { // Do not proceed any further since diagnostic is not enabled in the application configuration. return; } } } if (null == this.diagnosticMonitor) { // Configuration extension is not available by some reasons, let try and see if DiagnosticsConnectionString property is set in the configuration. string diagConnectionString = CloudEnvironment.GetConfigurationSettingValue(Resources.DiagnosticsConnectionStringSettingName); // If DiagnosticsConnectionString is defined, start a Diagnostic Monitor using the storage account configuration specified in the setting. if (!String.IsNullOrEmpty(diagConnectionString)) { this.diagnosticMonitor = DiagnosticMonitor.Start(diagConnectionString, GetDiagnosticMonitorDefaultConfiguration()); } } }