Exemplo n.º 1
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));
        }
Exemplo n.º 2
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);
        }