Reputation: 11344
I'm getting parse exceptions when using WindowsAzure.Storage to access storage analytics logs.
This is my code for retrieving log records:
var recordList = this.SourceAnalyticsClient.ListLogRecords(
this.Service, this.StartTime, null, this.Configuration.BlobRequestOptions,
this.CreateOperationContext())
.ToList();
That code throws the following exception:
Error parsing log record: could not parse 'Wednesday, 03-Dec-14 08:59:27 GMT' using format: dddd, dd-MMM-yy HH:mm:ss 'GMT' (type InvalidOperationException)
Exception stack trace:
at Microsoft.WindowsAzure.Storage.Analytics.LogRecordStreamReader.ReadDateTimeOffset(String format)
at Microsoft.WindowsAzure.Storage.Analytics.LogRecord.PopulateVersion1Log(LogRecordStreamReader reader)
at Microsoft.WindowsAzure.Storage.Analytics.LogRecord..ctor(LogRecordStreamReader reader)
I'm guessing this happens because my thread is not using an English culture.
I need a way to resolve this problem or a workaround.
Upvotes: 1
Views: 178
Reputation: 11344
After investing this a little bit I found that LogRecordStreamReader.ReadDateTimeOffset
is specifying a null
format provider parameter to DateTimeOffset.TryParseExact
. That means that the thread's current culture will be used - and that won't work for threads using non-English cultures.
A possible workaround is:
// 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;
}
I've also created a pull request with a suggested fix.
Upvotes: 1