Skip to content
This repository was archived by the owner on Nov 10, 2017. It is now read-only.

Commit 7084847

Browse files
committed
Moved logic for creating a blob to the data provider.
It's data provider responsibility to create a blob.
1 parent a857e4c commit 7084847

2 files changed

Lines changed: 7 additions & 17 deletions

File tree

src/Sitecore.Azure.Diagnostics/Appenders/AzureBlobStorageAppender.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,25 +106,9 @@ protected override void Append(LoggingEvent loggingEvent)
106106
var blob = this.Blob as CloudAppendBlob;
107107
string message = this.RenderLoggingEvent(loggingEvent);
108108

109-
CreateBlobIfNotExists(blob);
110109
blob.AppendText(message);
111110
}
112111

113-
/// <summary>
114-
/// Creates a new blob for the specified <see cref="CloudAppendBlob" /> if it does not already exist.
115-
/// </summary>
116-
/// <param name="blob">The <see cref="CloudAppendBlob" />.</param>
117-
/// <param name="accessCondition">The access condition.</param>
118-
/// <param name="blobRequestOptions">The blob request options.</param>
119-
/// <param name="operationContext">The operation context.</param>
120-
protected static void CreateBlobIfNotExists(CloudAppendBlob blob, AccessCondition accessCondition = null, BlobRequestOptions blobRequestOptions = null, OperationContext operationContext = null)
121-
{
122-
if (!blob.Exists(blobRequestOptions, operationContext))
123-
{
124-
blob.CreateOrReplace(accessCondition, blobRequestOptions, operationContext);
125-
}
126-
}
127-
128112
/// <summary>
129113
/// Gets the new cloud blob for diagnostic messages.
130114
/// </summary>

src/Sitecore.Azure.Diagnostics/Storage/AzureBlobStorageProvider.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,16 @@ public virtual ICloudBlob CreateBlob(string blobName)
254254
// Build blob name for a Role Environment using the following format: {DeploymentId}/{RoleInstanceId}/{BlobName}.
255255
blobName = string.IsNullOrEmpty(webRoleRelativeAddress) ? blobName : string.Format("{0}/{1}", webRoleRelativeAddress, blobName);
256256

257-
ICloudBlob blob = this.CloudBlobContainer.Exists() ?
257+
var blob = this.CloudBlobContainer.Exists() ?
258258
this.CloudBlobContainer.GetAppendBlobReference(blobName) :
259259
this.GetContainer(this.ContainerName).GetAppendBlobReference(blobName);
260260

261+
if (!blob.Exists())
262+
{
263+
// Create an empty append blob or throw an exception if the blob exists.
264+
blob.CreateOrReplace(AccessCondition.GenerateIfNotExistsCondition());
265+
}
266+
261267
return blob;
262268
}
263269

0 commit comments

Comments
 (0)