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

Commit a857e4c

Browse files
authored
Merge pull request #10 from ppluijten/master
Checking if append blobs exist before appending to them
2 parents 63aedbc + 2189eda commit a857e4c

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using log4net.Appender;
66
using log4net.spi;
7+
using Microsoft.WindowsAzure.Storage;
78
using Microsoft.WindowsAzure.Storage.Blob;
89
using Sitecore.Azure.Diagnostics.Storage;
910

@@ -105,9 +106,25 @@ protected override void Append(LoggingEvent loggingEvent)
105106
var blob = this.Blob as CloudAppendBlob;
106107
string message = this.RenderLoggingEvent(loggingEvent);
107108

109+
CreateBlobIfNotExists(blob);
108110
blob.AppendText(message);
109111
}
110112

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+
111128
/// <summary>
112129
/// Gets the new cloud blob for diagnostic messages.
113130
/// </summary>

0 commit comments

Comments
 (0)