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

Commit bc16cda

Browse files
committed
Changed the appender to use the buffer before logging events.
The appender inherits from the BufferingAppenderSkeleton class now. It allows sending a batch of logged events after a local buffer is filled. See more details here: https://logging.apache.org/log4net/release/sdk/index.html
1 parent d8b33b9 commit bc16cda

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
using Microsoft.WindowsAzure.Storage.Blob;
55
using Sitecore.Azure.Diagnostics.Storage;
66
using System;
7+
using System.Text;
78

89
namespace Sitecore.Azure.Diagnostics.Appenders
910
{
1011
/// <summary>
1112
/// Represents the appender that logs Sitecore diagnostic information to Microsoft Azure Blob storage service.
1213
/// </summary>
13-
public class AzureBlobStorageAppender : AppenderSkeleton
14+
public class AzureBlobStorageAppender : BufferingAppenderSkeleton
1415
{
1516
#region Fields
1617

@@ -71,6 +72,12 @@ private ICloudBlob Blob
7172
}
7273
}
7374

75+
if (!cloudBlob.Exists())
76+
{
77+
// Create an empty append blob or throw an exception if the blob exists.
78+
((CloudAppendBlob) cloudBlob).CreateOrReplace(AccessCondition.GenerateIfNotExistsCondition());
79+
}
80+
7481
return this.cloudBlob;
7582
}
7683
}
@@ -93,23 +100,23 @@ public AzureBlobStorageAppender()
93100
#region Protected Methods
94101

95102
/// <summary>
96-
/// Appends the specified logging event.
103+
/// Sends the buffer's events to be appended as one chunk of content in one go to the cloud blob.
97104
/// </summary>
98-
/// <param name="loggingEvent">The logging event.</param>
99-
protected override void Append(LoggingEvent loggingEvent)
105+
/// <param name="loggingEvents">The logging events.</param>
106+
protected override void SendBuffer(LoggingEvent[] loggingEvents)
100107
{
101-
Sitecore.Diagnostics.Assert.ArgumentNotNull(loggingEvent, "loggingEvent");
108+
Sitecore.Diagnostics.Assert.ArgumentNotNull(loggingEvents, "loggingEvents");
102109

103-
var blob = this.Blob as CloudAppendBlob;
110+
var content = new StringBuilder();
104111

105-
if (!blob.Exists())
112+
foreach (var loggingEvent in loggingEvents)
106113
{
107-
// Create an empty append blob or throw an exception if the blob exists.
108-
blob.CreateOrReplace(AccessCondition.GenerateIfNotExistsCondition());
114+
string message = this.RenderLoggingEvent(loggingEvent);
115+
content.Append(message);
109116
}
110117

111-
string message = this.RenderLoggingEvent(loggingEvent);
112-
blob.AppendText(message, LogStorageManager.DefaultTextEncoding, null, null, null);
118+
var blob = this.Blob as CloudAppendBlob;
119+
blob.AppendTextAsync(content.ToString(), LogStorageManager.DefaultTextEncoding, null, null, null);
113120
}
114121

115122
/// <summary>

0 commit comments

Comments
 (0)