44using Microsoft . WindowsAzure . Storage . Blob ;
55using Sitecore . Azure . Diagnostics . Storage ;
66using System ;
7+ using System . Text ;
78
89namespace 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