Пример #1
0
 protected void SendString(AppendBlobClient blob, string message)
 {
     using (MemoryStream ms = new MemoryStream(encoding.GetBytes(message)))
     {
         blob.AppendBlock(ms);
     }
 }
Пример #2
0
 protected void SendBytes(AppendBlobClient blob, byte[] msgBytes)
 {
     using (MemoryStream ms = new MemoryStream(msgBytes))
     {
         blob.AppendBlock(ms);
     }
 }
Пример #3
0
        private void ProcessEvent(LoggingEvent loggingEvent)
        {
            AppendBlobClient appendBlob = _cloudBlobContainer.GetAppendBlobClient(Filename(loggingEvent, _directoryName));
            var xml = loggingEvent.GetXmlString(Layout);

            using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
            {
                appendBlob.AppendBlock(ms);
            }
        }
Пример #4
0
        protected void SendFile(AppendBlobClient blob, string fileNameAndPath)
        {
            if (!File.Exists(fileNameAndPath))
            {
                throw new CantSendFileDataWhenFileDoesNotExistException(fileNameAndPath);
            }

            using (StreamReader sr = new StreamReader(fileNameAndPath))
            {
                blob.AppendBlock(sr.BaseStream);
            }
        }
Пример #5
0
        private void WriteLogLine(string line)
        {
            AppendBlobClient client = new AppendBlobClient(_connectionString, _containerName, LogFileStamped);

            client.CreateIfNotExists();

            lock (thisLock)
            {
                using (MemoryStream stream = new MemoryStream())
                    using (StreamWriter sw = new StreamWriter(stream))
                    {
                        sw.Write(line);
                        sw.Write("\n");
                        sw.Flush();
                        stream.Position = 0;
                        client.AppendBlock(stream);
                    }
            }
        }
Пример #6
0
        public void Flush()
        {
            var numSendBytes   = _bytesToSend.Length;
            var OrigSendBytes  = numSendBytes;
            var buffer         = _bytesToSend.GetBuffer();
            int bufferPosition = 0;

            while (numSendBytes > 0)
            {
                int numAppendBytes = (int)Math.Min(numSendBytes, 1024 * 1024);
                var sendStream     = new MemoryStream(buffer, bufferPosition, numAppendBytes);
                _logClient.AppendBlock(sendStream, null, _leaseCondition);
                bufferPosition += numAppendBytes;
                numSendBytes   -= numAppendBytes;
            }
            Debug.Assert(OrigSendBytes == _bytesToSend.Length);
            _bytesToSend.Position = 0;
            _bytesToSend.SetLength(0);
        }
Пример #7
0
        private async Task WriteLogAsync()
        {
            try
            {
                BlobContainerClient blobContainerClient = await CreateContainer();

                AppendBlobClient appendBlobClient = await CreateBlob(blobContainerClient);

                using (var ms = new MemoryStream())
                {
                    string     message = "";
                    TextWriter tw      = new StreamWriter(ms, Encoding.UTF8, appendBlobClient.AppendBlobMaxAppendBlockBytes);
                    while (!_logMessages.IsEmpty)
                    {
                        _logMessages.TryDequeue(out message);
                        tw.Write(message);
                    }
                    tw.Flush();
                    ms.Position = 0;
                    appendBlobClient.AppendBlock(ms);
                }
            }
            catch (Exception ex) { throw ex; }
        }
Пример #8
0
 protected void SendStream(AppendBlobClient blob, Stream stream)
 {
     blob.AppendBlock(stream);
 }