private async Task InitBlobPropertiesAsync() { try { await _blob.CreateOrReplaceAsync(AccessCondition.GenerateIfNotExistsCondition(), _blobRequestOptions, null); _blob.Properties.ContentType = "text/plain"; _blob.Properties.ContentEncoding = _blobEncoding.WebName; await _blob.SetPropertiesAsync(null, _blobRequestOptions, null); _blob.Metadata.Add(_compressedKey, _compressData.ToString()); _blob.Metadata.Add(_newFormatKey, true.ToString()); await _blob.SetMetadataAsync(null, _blobRequestOptions, null); } catch (StorageException) { } }
protected override void Write(LogEventInfo logEvent) { _client = _client ?? CloudStorageAccount.Parse(ConnectionString.Render(logEvent)).CreateCloudBlobClient(); if (_client == null) { return; } var containerName = Container.Render(logEvent); var blobName = BlobName.Render(logEvent); if (_container == null || _container.Name != containerName) { _container = _client.GetContainerReference(containerName); _container.CreateIfNotExistsAsync().Wait(); _blob = null; } if (_blob == null || _blob.Name != blobName || _forceCheck) { _blob = _container.GetAppendBlobReference(blobName); if (!_blob.ExistsAsync().Result) { try { _blob.Properties.ContentType = "text/plain"; _blob.CreateOrReplaceAsync().Wait(); _blob.SetPropertiesAsync().Wait(); } catch (StorageException ex) when(ex.RequestInformation.HttpStatusCode == (int)HttpStatusCode.Conflict) { // to be expected } } } _blob.AppendTextAsync(Layout.Render(logEvent) + "\r\n").Wait(); }