Ejemplo n.º 1
0
 /// <summary>
 ///     Selected the message template based on the azure storage result and the azure storage provider options
 /// </summary>
 /// <param name="azureStorageLogResult">The azure storage result </param>
 /// <param name="azureStorageLogProviderOptions">The azure storage provider options</param>
 /// <returns></returns>
 public static string ToMessageTemplate(this AzureStorageEventLogResult azureStorageLogResult,
                                        AzureStorageLogProviderOptions azureStorageLogProviderOptions)
 {
     return(azureStorageLogResult.IsStored
         ? azureStorageLogProviderOptions.SuccessfulMessageTemplate
         : azureStorageLogProviderOptions.FailedMessageTemplate);
 }
Ejemplo n.º 2
0
        public void Test_ValidateSasUrl_ValidUrl()
        {
            var url    = "https://test/test/test/";
            var result = new AzureStorageLogProviderOptions(url, true, resourcesFactory.SuccessTemplateMessage, resourcesFactory.FailureTemplateMessage);

            Assert.IsNotNull(result.AzureStorageContainerSasUrl);
            Assert.AreEqual(result.AzureStorageContainerSasUrl.AbsoluteUri, url);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Creates a json log entry string from an azure storage log result
        /// </summary>
        /// <param name="azureStorageLogResult">The azure log storage result</param>
        /// <param name="azureStorageLogProviderOptions">The azure log provider options</param>
        /// <param name="existingLogEntry">The azure log entry</param>
        /// <param name="jsonSettings">The json serialization settings</param>
        /// <returns>The log entry string</returns>
        public static string ToJsonLogEntryString(this AzureStorageEventLogResult azureStorageLogResult,
                                                  AzureStorageLogProviderOptions azureStorageLogProviderOptions,
                                                  LogEntry existingLogEntry,
                                                  JsonSerializerSettings jsonSettings)
        {
            var template   = azureStorageLogResult.ToMessageTemplate(azureStorageLogProviderOptions);
            var logMessage = azureStorageLogResult.ToLogMessage(azureStorageLogProviderOptions, template);

            existingLogEntry.MessageTemplate = template;
            existingLogEntry.Exception       = new Exception(logMessage);
            existingLogEntry.LogProperties   = null;
            return(JsonConvert.SerializeObject(existingLogEntry, jsonSettings));
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Creates a log message based on the azure storage log result
        /// </summary>
        /// <param name="azureStorageLogResult">The azure storage result</param>
        /// <param name="azureStorageLogProviderOptions">The azure storage log provider options</param>
        /// <param name="template">The template</param>
        /// <returns>The azure storage log message</returns>
        public static string ToLogMessage(this AzureStorageEventLogResult azureStorageLogResult,
                                          AzureStorageLogProviderOptions azureStorageLogProviderOptions,
                                          string template)
        {
            var sb = new StringBuilder(template);

            foreach (var prop in azureStorageLogResult.GetType().GetProperties())
            {
                var oldValue = string.Format("{0}{1}{2}", "{{", prop.Name, "}}");
                var value    = prop.GetValue(azureStorageLogResult, null);
                var newValue = value != null?value.ToString() : null;

                sb.Replace(oldValue, newValue);
            }

            return(sb.ToString());
        }
Ejemplo n.º 5
0
        public void Test_ToJsonLogEntryString()
        {
            var  requestId    = Guid.NewGuid().ToString();
            var  sha          = Guid.NewGuid().ToString();
            var  reasonPhrase = "Tested";
            var  statusCode   = 201;
            var  isStored     = true;
            var  modifiedDate = DateTime.UtcNow;
            long fileSize     = 12345678;
            var  dt           = DateTime.UtcNow;
            var  blobFullName = string.Format("{0}.{1}", Guid.NewGuid().ToString().Replace("-", "_"), "blob");
            var  azureStorageEventLogResult     = new AzureStorageEventLogResult(reasonPhrase, statusCode, requestId, sha, isStored, blobFullName, fileSize, modifiedDate);
            var  azureStorageLogProviderOptions =
                new AzureStorageLogProviderOptions("https://test.com", true, resourcesFactory.SuccessTemplateMessage, resourcesFactory.FailureTemplateMessage);
            var logEntry = new LogEntry
            {
                Exception       = new Exception(""),
                Level           = "Warning",
                MessageTemplate = "Log Serialization failed with exception",
                Timestamp       = dt,
                EventId         = new EventId(7437)
            };
            var jsonSettings = new JsonSerializerSettings
            {
                Formatting            = Formatting.Indented,
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                ContractResolver      = new NullPropertyResolver()
            };
            var result           = azureStorageEventLogResult.ToJsonLogEntryString(azureStorageLogProviderOptions, logEntry, jsonSettings);
            var expectedTemplate =
                "Azure Storage Logging: A blob with the error details was created at {{BlobFullName}}. Reason: ErrorMessageEqualOrGreaterTo1MB ResponseMessage: {{ReasonPhrase}} ResponseCode: {{StatusCode}} RequestId: {{RequestId}} Sha256: {{FileSHA}} FileSize(Bs): {{FileSize}} FileModifiedDate: {{ModifiedDate}}";
            var expectedMessage =
                $"Azure Storage Logging: A blob with the error details was created at {blobFullName}. Reason: ErrorMessageEqualOrGreaterTo1MB ResponseMessage: {reasonPhrase} ResponseCode: {statusCode} RequestId: {requestId} Sha256: {sha} FileSize(Bs): {fileSize} FileModifiedDate: {modifiedDate}";
            var expectedLogEntry = new LogEntry
            {
                Exception       = new Exception(expectedMessage),
                Level           = "Warning",
                MessageTemplate = expectedTemplate,
                Timestamp       = dt,
                EventId         = new EventId(7437)
            };
            var expectedJsonString = JsonConvert.SerializeObject(expectedLogEntry, jsonSettings);

            Assert.AreEqual(expectedJsonString, result);
        }
Ejemplo n.º 6
0
        public void Test_ToMessageTemplate_Success()
        {
            var options = new AzureStorageLogProviderOptions("https://test.com", true, resourcesFactory.SuccessTemplateMessage, resourcesFactory.FailureTemplateMessage);

            var  requestId    = Guid.NewGuid().ToString();
            var  sha          = Guid.NewGuid().ToString();
            var  reasonPhrase = "Tested";
            var  statusCode   = 201;
            var  isStored     = true;
            var  modifiedDate = DateTime.UtcNow;
            long fileSize     = 12345678;
            var  blobFullName = string.Format("{0}.{1}", Guid.NewGuid().ToString().Replace("-", "_"), "blob");
            var  azureStorageEventLogResult = new AzureStorageEventLogResult(reasonPhrase, statusCode, requestId, sha, isStored, blobFullName, fileSize, modifiedDate);

            var result   = azureStorageEventLogResult.ToMessageTemplate(options);
            var expected =
                "Azure Storage Logging: A blob with the error details was created at {{BlobFullName}}. Reason: ErrorMessageEqualOrGreaterTo1MB ResponseMessage: {{ReasonPhrase}} ResponseCode: {{StatusCode}} RequestId: {{RequestId}} Sha256: {{FileSHA}} FileSize(Bs): {{FileSize}} FileModifiedDate: {{ModifiedDate}}";

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 7
0
        public EventHubClientWrapper(string eventHubConnectionString, string eventHubEntityPath, AzureStorageLogProviderOptions azureStorageLogProviderOptions)
        {
            var connectionStringBuilder = new EventHubsConnectionStringBuilder(eventHubConnectionString)
            {
                EntityPath = eventHubEntityPath
            };

            eventHubClient = EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());
            var azureStorageBlobContainerBuilder = new AzureStorageBlobContainerBuilder(azureStorageLogProviderOptions);

            azureStorageBlobContainerBuilder.Build();
            this.AzureStorageBlobContainerBuilder = azureStorageBlobContainerBuilder;
        }