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

Commit ab2aee4

Browse files
committed
Fixed Issue #3.
Replaced the BlockBlob with AppendBlob.
1 parent 819636c commit ab2aee4

4 files changed

Lines changed: 19 additions & 46 deletions

File tree

src/Sitecore.Azure.Diagnostics.UI/sitecore/Shell/Applications/Reports/LogViewer/LogViewerDetailsForm.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ protected override void OnLoad(EventArgs e)
5656
var blob = LogStorageManager.GetBlob(blobName);
5757
var data = string.Empty;
5858

59-
if (blob.BlobType == BlobType.BlockBlob)
59+
if (blob.BlobType == BlobType.AppendBlob)
6060
{
61-
data = ((CloudBlockBlob)blob).DownloadText(LogStorageManager.DefaultTextEncoding);
61+
data = ((CloudAppendBlob)blob).DownloadText(LogStorageManager.DefaultTextEncoding);
6262
}
6363

6464
if (string.IsNullOrEmpty(data))

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

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public class AzureBlobStorageAppender : AppenderSkeleton
3333
public DateTime CurrentDate { get; protected set; }
3434

3535
/// <summary>
36-
/// The cloud block BLOB for storing log entries.
36+
/// The cloud BLOB for storing log entries.
3737
/// </summary>
38-
private ICloudBlob cloudBlockBlob;
38+
private ICloudBlob cloudBlob;
3939

4040
#endregion
4141

@@ -45,21 +45,21 @@ public class AzureBlobStorageAppender : AppenderSkeleton
4545
/// Gets the BLOB.
4646
/// </summary>
4747
/// <value>
48-
/// The cloud block BLOB.
48+
/// The cloud BLOB.
4949
/// </value>
5050
private ICloudBlob Blob
5151
{
5252
get
5353
{
5454
// Create a new blob if this is the first time it is used.
55-
if (this.cloudBlockBlob == null)
55+
if (this.cloudBlob == null)
5656
{
57-
this.cloudBlockBlob = this.GetNewBlob();
57+
this.cloudBlob = this.GetNewBlob();
5858
}
5959
// Recreate a blob if a container is no longer exists.
60-
else if (!this.cloudBlockBlob.Container.Exists())
60+
else if (!this.cloudBlob.Container.Exists())
6161
{
62-
this.cloudBlockBlob = LogStorageManager.GetBlob(this.cloudBlockBlob.Name);
62+
this.cloudBlob = LogStorageManager.GetBlob(this.cloudBlob.Name);
6363
}
6464
// Create a new blob if the current shouldn't be used.
6565
else
@@ -69,11 +69,11 @@ private ICloudBlob Blob
6969

7070
if (needNewBlob)
7171
{
72-
this.cloudBlockBlob = this.GetNewBlob();
72+
this.cloudBlob = this.GetNewBlob();
7373
}
7474
}
7575

76-
return this.cloudBlockBlob;
76+
return this.cloudBlob;
7777
}
7878
}
7979

@@ -102,44 +102,17 @@ protected override void Append(LoggingEvent loggingEvent)
102102
{
103103
Sitecore.Diagnostics.Assert.ArgumentNotNull(loggingEvent, "loggingEvent");
104104

105-
var blob = this.Blob as CloudBlockBlob;
105+
var blob = this.Blob as CloudAppendBlob;
106106
string message = this.RenderLoggingEvent(loggingEvent);
107107

108-
this.AddMessageToBlock(blob, message);
109-
}
110-
111-
/// <summary>
112-
/// Adds the diagnostic message to block blob.
113-
/// </summary>
114-
/// <param name="blob">The cloud blob.</param>
115-
/// <param name="message">The message.</param>
116-
protected virtual void AddMessageToBlock(CloudBlockBlob blob, string message)
117-
{
118-
Sitecore.Diagnostics.Assert.ArgumentNotNull(blob, "blob");
119-
Sitecore.Diagnostics.Assert.ArgumentNotNull(message, "message");
120-
121-
var blockIds = new List<string>();
122-
123-
if (blob.Exists())
124-
{
125-
blockIds.AddRange(blob.DownloadBlockList().Select(b => b.Name));
126-
}
127-
128-
string blockId = Guid.NewGuid().ToString().Replace("-", string.Empty);
129-
blockIds.Add(blockId);
130-
131-
using (var blockData = new MemoryStream(LogStorageManager.DefaultTextEncoding.GetBytes(message), false))
132-
{
133-
blob.PutBlock(blockId, blockData, null);
134-
blob.PutBlockList(blockIds);
135-
}
136-
}
108+
blob.AppendText(message);
109+
}
137110

138111
/// <summary>
139112
/// Gets the new cloud blob for diagnostic messages.
140113
/// </summary>
141114
/// <returns>
142-
/// The cloud block blob.
115+
/// The cloud blob.
143116
/// </returns>
144117
protected virtual ICloudBlob GetNewBlob()
145118
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ public virtual ICloudBlob CreateBlob(string blobName)
245245
blobName = string.IsNullOrEmpty(webRoleRelativeAddress) ? blobName : string.Format("{0}/{1}", webRoleRelativeAddress, blobName);
246246

247247
ICloudBlob blob = this.CloudBlobContainer.Exists() ?
248-
this.CloudBlobContainer.GetBlockBlobReference(blobName) :
249-
this.GetContainer(this.ContainerName).GetBlockBlobReference(blobName);
248+
this.CloudBlobContainer.GetAppendBlobReference(blobName) :
249+
this.GetContainer(this.ContainerName).GetAppendBlobReference(blobName);
250250

251251
return blob;
252252
}

src/Sitecore.Azure.Diagnostics/Tasks/BlobCleaner.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ protected ICollection<ICloudBlob> GetCandidateBlobs(CloudBlobContainer container
152152
/// <summary>
153153
/// Gets the BLOB age. The time since last modification.
154154
/// </summary>
155-
/// <param name="blob">The cloud block BLOB.</param>
155+
/// <param name="blob">The cloud BLOB.</param>
156156
/// <returns></returns>
157157
protected TimeSpan GetBlobAge(ICloudBlob blob)
158158
{
@@ -164,7 +164,7 @@ protected TimeSpan GetBlobAge(ICloudBlob blob)
164164
/// <summary>
165165
/// Gets the BLOB time (max of last modified)
166166
/// </summary>
167-
/// <param name="blob">The cloud block BLOB.</param>
167+
/// <param name="blob">The cloud BLOB.</param>
168168
/// <returns></returns>
169169
protected DateTime GetBlobLastModifiedDate(ICloudBlob blob)
170170
{

0 commit comments

Comments
 (0)