private static async Task LogContentAsync(StringBuilder log, HttpContent httpContent) { if (httpContent != null) { log.AppendLine(" CONTENT HEADERS: "); LogHeaders(log, httpContent.Headers); if (httpContent.IsPlainText() || httpContent.IsHtmlText() || httpContent.IsJson() || httpContent.IsFormUrlEncoded()) { var content = await httpContent.ReadAsStringAsync(); StorageFolder folder = null; try { folder = (await ApplicationData.Current.LocalFolder.GetFoldersAsync()) .FirstOrDefault(x => string.Equals(x.Name, WebResponseLogs, StringComparison.OrdinalIgnoreCase)); } catch (InvalidOperationException) { // Unit tests does not have package identity. We just ignore them. } if (folder != null) { var fileName = string.Format("{0}.log", Guid.NewGuid()); var file = await folder.CreateFileAsync(fileName); await FileIO.WriteTextAsync(file, content); log.AppendFormat(" CONTENT FILE: {0}", file.Path); } else { log.AppendFormat(" CONTENT:{0}{1}", Environment.NewLine, content.Substring(0, Math.Min(4096, content.Length))); log.AppendLine(); log.AppendFormat(" ENDCONTENT."); log.AppendLine(); } } } else { log.AppendLine(" CONTENT IS NULL."); } }