2014-12-03 65 views
1

当使用WindowsAzure.Storage访问存储分析日志时,我收到了解析异常。Azure存储分析日志解析错误

这是我的检索日志记录代码:

var recordList = this.SourceAnalyticsClient.ListLogRecords(
    this.Service, this.StartTime, null, this.Configuration.BlobRequestOptions, 
    this.CreateOperationContext()) 
    .ToList(); 

该代码引发以下异常:

错误解析日志记录:无法解析“周三,03日 - 12月14格式为:dddd,dd-MMM-yy HH:mm:ss'GMT'(类型InvalidOperationException)
异常堆栈跟踪:
at Microsoft.WindowsAzure.Storage.Anal ytics.LogRecordStreamReader.ReadDateTimeOffset(字符串格式)
在Microsoft.WindowsAzure.Storage.Analytics.LogRecord.PopulateVersion1Log(LogRecordStreamReader读取器)
在Microsoft.WindowsAzure.Storage.Analytics.LogRecord..ctor(LogRecordStreamReader读取器)

我猜这是因为我的线程没有使用英语文化。

我需要一种方法来解决此问题或解决方法。

回答

1

在投资了这一点之后,我发现LogRecordStreamReader.ReadDateTimeOffset指定了一个null格式提供程序参数为DateTimeOffset.TryParseExact。这意味着该线程的当前文化将被使用 - 而这对于使用非英语文化的线程将无效。

可能的解决方法是:

// 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; 
} 

我还创建了一个pull request with a suggested fix