C# Azure存储分析日志分析错误
我在使用访问存储分析日志时遇到解析异常 这是我检索日志记录的代码:C# Azure存储分析日志分析错误,c#,azure,azure-storage,C#,Azure,Azure Storage,我在使用访问存储分析日志时遇到解析异常 这是我检索日志记录的代码: var recordList = this.SourceAnalyticsClient.ListLogRecords( this.Service, this.StartTime, null, this.Configuration.BlobRequestOptions, this.CreateOperationContext()) .ToList(); 该代码引发以下异常: 解析日志记录时出错:无法使用以
var recordList = this.SourceAnalyticsClient.ListLogRecords(
this.Service, this.StartTime, null, this.Configuration.BlobRequestOptions,
this.CreateOperationContext())
.ToList();
该代码引发以下异常:
解析日志记录时出错:无法使用以下格式解析“周三,2014年12月3日08:59:27 GMT”:dddd-MMM-yy-HH:mm:ss“GMT”(键入invalidoOperationException)异常堆栈跟踪:
位于Microsoft.WindowsAzure.Storage.Analytics.LogRecordStreamReader.ReadDateTimeOffset(字符串格式)
位于Microsoft.WindowsAzure.Storage.Analytics.LogRecord.PopulateVersion1Log(LogRecordStreamReader阅读器)
位于Microsoft.WindowsAzure.Storage.Analytics.LogRecord..ctor(LogRecordStreamReader阅读器) 我猜这是因为我的帖子没有使用英国文化
我需要一种方法来解决这个问题或解决方法。在做了一点投资后,我发现
LogRecordStreamReader.ReadDateTimeOffset
正在为DateTimeOffset.TryParseExact
指定一个null
格式提供程序参数。这意味着将使用线程的当前区域性,而这对于使用非英语区域性的线程不起作用
一种可能的解决方法是:
// Remember current culture setting
CultureInfo originalThreadCulture = Thread.CurrentThread.CurrentCulture;
try
{
// Assign the invariant culture temporarily
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
// Let WindowsAzure.Storage parse log records
recordList = this.SourceAnalyticsClient.ListLogRecords(
this.Service, this.StartTime, null, this.Configuration.BlobRequestOptions,
this.CreateOperationContext())
.ToList();
}
finally
{
// Restore original culture setting
Thread.CurrentThread.CurrentCulture = originalThreadCulture;
}
我还创建了一个