我正在使用下面的附加程序通过Log4Net将日志消息通过管道传输到Azure。 一切正常,直到blob文件达到5.4MB的大小为止。从此以后,不再将日志追加到日志文件。
是什么原因造成的?我该如何解决呢?
namespace Digicreate.Core.Infrastructure.Logging
{
using System;
using System.Configuration;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using log4net.Appender;
using log4net.Config;
using log4net.Core;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
// ReSharper disable once UnusedMember.Global
// justification: used in log4net configuration file
public class AzureBlobTxtFileAppender : BufferingAppenderSkeleton
{
private CloudStorageAccount _account;
...removed unimportant code...
protected override void SendBuffer(LoggingEvent[] events)
{
var appendBlobReference = _cloudBlobContainer.GetAppendBlobReference(Filename(DirectoryName));
if (!appendBlobReference.Exists())
{
appendBlobReference.CreateOrReplace();
}
Parallel.ForEach(events, ProcessEvent);
}
private static string Filename(string directoryName)
{
return $"{directoryName}/{DateTime.Today.ToString("yyyy_MM_dd", DateTimeFormatInfo.InvariantInfo)}.log.txt";
}
private void ProcessEvent(LoggingEvent loggingEvent)
{
using (var memoryStream = new MemoryStream())
{
using (var streamWriter = new StreamWriter(memoryStream, Encoding.UTF8, 1024, true))
{
Layout.Format(streamWriter, loggingEvent);
streamWriter.Flush();
}
memoryStream.Position = 0;
_cloudBlobContainer
.GetAppendBlobReference(Filename(DirectoryName))
.AppendBlock(memoryStream);
}
}
}
}
答案 0 :(得分:2)