public static ICommandingDependencyResolver UseMicrosoftLoggingExtensionsAuditor(this ICommandingDependencyResolver resolver,
                                                                                         LogLevel normalLogLevel           = LogLevel.Trace,
                                                                                         LogLevel executionFailureLogLevel = LogLevel.Warning,
                                                                                         MicrosoftLoggingExtensionsAuditorOptions options = null)
        {
            options = options ?? new MicrosoftLoggingExtensionsAuditorOptions();
            ILogLevelProvider logLevelProvider = new LogLevelProvider(normalLogLevel, executionFailureLogLevel);

            resolver.RegisterInstance(logLevelProvider);

            if (options.UsePreDispatchAuditor)
            {
                resolver.UsePreDispatchCommandingAuditor <LoggerCommandAuditor>(options.AuditPreDispatchRootOnly);
            }
            if (options.UsePostDispatchAuditor)
            {
                resolver.UsePostDispatchCommandingAuditor <LoggerCommandAuditor>(options.AuditPostDispatchRootOnly);
            }
            if (options.UsePreDispatchAuditor)
            {
                resolver.UseExecutionCommandingAuditor <LoggerCommandAuditor>(options.AuditExecuteDispatchRootOnly);
            }

            return(resolver);
        }
Exemple #2
0
        /// <summary>
        /// Registers a command auditor that writes to an event hub
        /// </summary>
        /// <param name="resolver">Dependency resolver</param>
        /// <param name="eventHubClient">The event hub client</param>
        /// <param name="partitionKeyProvider">An optional partition key provider, if unspecified events will be sent unpartitioned</param>
        /// <param name="options">Options for the event hub auditor configuration</param>
        /// <returns>Dependency resolver</returns>
        public static ICommandingDependencyResolver UseEventHubCommandAuditing(this ICommandingDependencyResolver resolver,
                                                                               Microsoft.Azure.EventHubs.EventHubClient eventHubClient,
                                                                               IPartitionKeyProvider partitionKeyProvider = null,
                                                                               AzureEventHubAuditorOptions options        = null)
        {
            options = options ?? new AzureEventHubAuditorOptions();
            IEventHubClient client = new EventHubClient(eventHubClient);

            if (partitionKeyProvider == null)
            {
                partitionKeyProvider = new NullPartitionKeyProvider();
            }

            resolver.RegisterInstance(client);
            resolver.RegisterInstance(partitionKeyProvider);
            resolver.TypeMapping <IAuditItemMapper, AuditItemMapper>();
            resolver.TypeMapping <IEventHubSerializer, EventHubSerializer>();
            if (options.UsePreDispatchAuditor)
            {
                resolver.UsePreDispatchCommandingAuditor <AzureEventHubCommandAuditor>(options.AuditPreDispatchRootOnly);
            }
            if (options.UsePostDispatchAuditor)
            {
                resolver.UsePostDispatchCommandingAuditor <AzureEventHubCommandAuditor>(options.AuditPostDispatchRootOnly);
            }
            if (options.UseExecutionAuditor)
            {
                resolver.UseExecutionCommandingAuditor <AzureEventHubCommandAuditor>(options.AuditExecuteDispatchRootOnly);
            }
            return(resolver);
        }
Exemple #3
0
        /// <summary>
        /// Sets up azure storage command auditing for output to a queue. This is best suited for scenarios
        /// where there are multiple auditors or storage mechanisms in the audit pipeline as it enables
        /// execution of the command dispatch pipeline to rapidly continue but still with a guarantee
        /// that the command will be audited.
        ///
        /// Generally when configuring this auditor no other auditors are configured - but you can.
        /// </summary>
        /// <param name="dependencyResolver">The dependency resolver</param>
        /// <param name="queue">The queue to audit via</param>
        /// <param name="blobContainer">The blob container to store the payload to. If this is set then the
        /// payload is stored before the item is queued, if left null then the payload will be serialized
        /// into the queue item. The default setting of null is the more performant and common case, setting
        /// the container here is only useful for very large command payloads that won't fit inside a queue
        /// item. If the payload is stored in the blob container specified here then there will be no way
        /// for downstream auditors to access it from the AuditItem model - it will be null.
        /// </param>
        /// <param name="storageStrategy"></param>
        /// <returns></returns>
        public static ICommandingDependencyResolver UseAzureStorageCommandAuditing(this ICommandingDependencyResolver dependencyResolver,
                                                                                   CloudQueue queue,
                                                                                   CloudBlobContainer blobContainer   = null,
                                                                                   IStorageStrategy storageStrategy   = null,
                                                                                   AzureStorageAuditorOptions options = null)
        {
            options = options ?? new AzureStorageAuditorOptions();
            ICloudAuditQueueProvider cloudAuditQueueProvider = new CloudAuditQueueProvider(queue, null);
            ICloudAuditQueueBlobContainerProvider cloudAuditQueueBlobContainerProvider = new CloudAuditQueueBlobContainerProvider(blobContainer);

            dependencyResolver.RegisterInstance(cloudAuditQueueProvider);
            dependencyResolver.RegisterInstance(cloudAuditQueueBlobContainerProvider);
            dependencyResolver.TypeMapping <IAzureStorageQueueSerializer, AzureStorageQueueSerializer>();
            if (options.UsePreDispatchAuditor)
            {
                dependencyResolver.UsePreDispatchCommandingAuditor <AzureStorageQueueCommandAuditor>(options.AuditPreDispatchRootOnly);
            }
            if (options.UsePostDispatchAuditor)
            {
                dependencyResolver.UsePostDispatchCommandingAuditor <AzureStorageQueueCommandAuditor>(options.AuditPostDispatchRootOnly);
            }
            if (options.UseExecutionAuditor)
            {
                dependencyResolver.UseExecutionCommandingAuditor <AzureStorageQueueCommandAuditor>(options.AuditExecuteDispatchRootOnly);
            }
            return(dependencyResolver);
        }
 public static IServiceCollection UseCoreCommanding(this IServiceCollection serviceCollection,
                                                    ICommandingDependencyResolver commandingDependencyResolver)
 {
     serviceCollection.AddSingleton <IMetricCollector>(new MetricCollector());
     commandingDependencyResolver
     .UsePreDispatchCommandingAuditor <LoggingCommandPreDispatchAuditor>()
     .UseExecutionCommandingAuditor <LoggingCommandExecutionAuditor>()
     .UseAuditItemEnricher <AuditItemUserIdEnricher>();
     return(serviceCollection);
 }
Exemple #5
0
        /// <summary>
        /// Sets up azure storage command auditing for direct output to tables
        /// </summary>
        /// <param name="dependencyResolver">The dependency resolver</param>
        /// <param name="cloudStorageAccount">The cloud storage account to use for storage</param>
        /// <param name="commandPayloadContainer">(Optional) The blob container that </param>
        /// <param name="storageStrategy"></param>
        /// <param name="options">Auditor options</param>
        /// <returns></returns>
        public static ICommandingDependencyResolver UseAzureStorageCommandAuditing(this ICommandingDependencyResolver dependencyResolver,
                                                                                   CloudStorageAccount cloudStorageAccount,
                                                                                   CloudBlobContainer commandPayloadContainer = null,
                                                                                   IStorageStrategy storageStrategy           = null,
                                                                                   AzureStorageAuditorOptions options         = null)
        {
            options = options ?? new AzureStorageAuditorOptions();

            if (!options.UseExecutionAuditor && !options.UsePostDispatchAuditor && !options.UsePreDispatchAuditor)
            {
                throw new AzureStorageConfigurationException("At least one auditor type must be configured");
            }
            CloudTableClient cloudTableClient = cloudStorageAccount.CreateCloudTableClient();

            if (commandPayloadContainer == null)
            {
                commandPayloadContainer = cloudStorageAccount.CreateCloudBlobClient().GetContainerReference("commandauditpayload");
            }
            if (storageStrategy == null)
            {
                storageStrategy = new SingleTableStrategy();
            }

            ICloudStorageProvider cloudStorageProvider = new CloudStorageProvider(cloudTableClient, commandPayloadContainer);

            dependencyResolver.RegisterInstance(cloudStorageProvider);
            dependencyResolver.RegisterInstance(storageStrategy);
            if (options.UsePreDispatchAuditor)
            {
                dependencyResolver.UsePreDispatchCommandingAuditor <AzureStorageTableCommandAuditor>(options.AuditPreDispatchRootOnly);
            }
            if (options.UsePostDispatchAuditor)
            {
                dependencyResolver.UsePostDispatchCommandingAuditor <AzureStorageTableCommandAuditor>(options.AuditPostDispatchRootOnly);
            }
            if (options.UseExecutionAuditor)
            {
                dependencyResolver.UseExecutionCommandingAuditor <AzureStorageTableCommandAuditor>(options.AuditExecuteDispatchRootOnly);
            }

            return(dependencyResolver);
        }