【发布时间】:2016-09-15 05:26:24
【问题描述】:
我想将条目写入存储在 Azure 文件存储中的日志文件。我目前有这个:
var log = "My log entry";
var client = _storageAccount.CreateCloudFileClient();
var share = client.GetShareReference(Config.LogShare);
share.CreateIfNotExists();
var root = share.GetRootDirectoryReference();
var logfile = root.GetFileReference("log.txt");
if (!logfile.Exists()) logfile.Create(0);
// What goes here to append to the file...?
我可以看到很多关于如何使用 Blob 执行此操作的示例,或者如何上传整个文件,但我如何仅追加到现有文件?
我试过这个:
var buffer = Encoding.GetEncoding("UTF-8").GetBytes(log.ToCharArray());
using (var fileStream = logfile.OpenWrite(0)) {
fileStream.Write(buffer, (int)logfile.Properties.Length, buffer.Length);
}
然后我得到这个错误:
The remote server returned an error: (416) The range specified is invalid for the current size of the resource..
【问题讨论】:
标签: file append azure-storage