Azure存储分析日志解析错误

时间:2014-12-03 10:07:44

标签: c# azure azure-storage

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

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

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

该代码抛出以下异常:

  

解析日志记录时出错:无法解析'星期三,03-Dec-14 08:59:27 GMT'使用格式:dddd,dd-MMM-yy HH:mm:ss'GMT'(输入InvalidOperationException)
  异常堆栈跟踪:
     在Microsoft.WindowsAzure.Storage.Analytics.LogRecordStreamReader.ReadDateTimeOffset(String format)
     在Microsoft.WindowsAzure.Storage.Analytics.LogRecord.PopulateVersion1Log(LogRecordStreamReader reader)
     在Microsoft.WindowsAzure.Storage.Analytics.LogRecord..ctor(LogRecordStreamReader reader)

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

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

1 个答案:

答案 0 :(得分: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

相关问题