Semantic Logging Out of process custom sink not logging large size data

Topics: Logging Application Block, Semantic Logging Application Block, Transient Fault Handling Application Block ("Topaz")
Dec 15, 2014 at 11:02 AM
Edited Dec 15, 2014 at 11:18 AM
Hi Team,

Below is the custom sink code for log data into log file(blob). This is working fine for bigger size string when we run it as in process. but when I tried running this in out of process, it throwing proxy authentication error 407.


see my bcustom sink code. kindly help me to fix.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Practices.EnterpriseLibrary.SemanticLogging;
using Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Formatters;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System.Globalization;
using System.IO;
using Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling;
using Microsoft.WindowsAzure.Storage.RetryPolicies;

namespace SemanticLogging.CustomSink
{
public class AzureBlobSink : IObserver<EventEntry> 
{

    private readonly IEventTextFormatter _formatter;

    private string ConnectionString { get; set; }

    private string ContainerName { get; set; }

    private string BlobName { get; set; }



    public AzureBlobSink(string connectionString, string containerName, string blobname)
    {
        this.ConnectionString = connectionString;
        this.ContainerName = containerName;
        this.BlobName = blobname;
        _formatter = new EventTextFormatter();
    }

    public void OnCompleted()
    {
        //throw new NotImplementedException();
        //base.Dispose();
    }

    public void OnError(Exception error)
    {
        //throw new NotImplementedException();
        SemanticLoggingEventSource.Log.CustomSinkUnhandledFault("Exception: " + error.Message + Environment.NewLine + "Stack trace:" + error.StackTrace + Environment.NewLine + "Inner Exception" + error.InnerException + Environment.NewLine);
    }

    public void OnNext(EventEntry value)
    {
        if (value != null)
        {
            using (var writer = new StringWriter())
            {
                _formatter.WriteEvent(value, writer);
                Postdata(Convert.ToString(writer), BlobName);
            }
        }
    }

    /// <summary>
    /// create container and upsert block blob content
    /// </summary>
    /// <param name="content"></param>
    private void Postdata(string content, string blobname)
    {
        List<string> blockIds = new List<string>();
        var bytesToUpload = Encoding.UTF8.GetBytes(content);

        try
        {
            using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(content)))
            {
                CloudStorageAccount account = CloudStorageAccount.Parse(ConnectionString);
                CloudBlobClient blobClient = account.CreateCloudBlobClient();
                //linear Retry Policy create a blob container 10 times. The backoff duration is 2 seconds 
                IRetryPolicy linearRetryPolicy = new LinearRetry(TimeSpan.FromSeconds(2), 15);
                //exponential Retry Policy which retries the code to create a blob container 10 times.
                IRetryPolicy exponentialRetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(2), 15);
                blobClient.RetryPolicy = exponentialRetryPolicy;
                //
                CloudBlobContainer container = blobClient.GetContainerReference(ContainerName);
                container.CreateIfNotExists();
                CloudBlockBlob blob = container.GetBlockBlobReference(blobname + System.DateTime.UtcNow.ToString("MMddyyyy") + ".log");
                stream.Seek(0, SeekOrigin.Begin);

                if (!blob.Exists())
                {
                    using (var insertempty = new MemoryStream(Encoding.UTF8.GetBytes("")))
                    {
                        insertempty.Seek(0, SeekOrigin.Begin);
                        blob.UploadFromStream(insertempty);
                    }
                }

                blockIds.AddRange(blob.DownloadBlockList(BlockListingFilter.Committed).Select(b => b.Name));
                var newId = Convert.ToBase64String(Encoding.UTF8.GetBytes(blockIds.Count.ToString(CultureInfo.InvariantCulture).PadLeft(64, '0')), Base64FormattingOptions.None);
                //var newId = Convert.ToBase64String(Encoding.Default.GetBytes(blockIds.Count.ToString()));
                blob.PutBlock(newId, new MemoryStream(bytesToUpload), null);
                blockIds.Add(newId);
                blob.PutBlockList(blockIds);

            }
        }
        catch (Exception ex)
        {
            SemanticLoggingEventSource.Log.CustomSinkUnhandledFault("Exception: " + ex.Message + Environment.NewLine + "Stack trace:" + ex.StackTrace + Environment.NewLine + "Inner Exception" + ex.InnerException + Environment.NewLine);
            //logerror("Exception: " + ex.Message + Environment.NewLine + "Stack trace:" + ex.StackTrace + Environment.NewLine + "Inner Exception" + ex.InnerException + Environment.NewLine);
        }
    }

    private void logerror(string error)
    {
        Postdata(error, "semanticinprocesserrorlog");
    }

}
}




Below are the error message I received,


opcode: info
task: 65533
version: 0
Payload: [message : Exception: The remote server returned an error: (407) Proxy Authentication required.
Inner Exception: System.net.webException: The remote server returned an error: (407) Proxy authentication required.
at system.net.httpwebrequest.getresponse()
at microsoft.windowsazure.storage.core.executor.executor.executesync[t](storagecommandbase
'1 cmd, IRetryPolicy policy, OperationContext operationContext)]
Eventname: CustomSinkUnhandledFaultInfo
Timestamp: 2014-12-15T11:17:357353172z


Kindly help me to resolve.