private async Task OnExecuteAsync() { var fullPath = Path.GetFullPath(OutputFilePath); var getRangeResult = RangeParser.TryGetRange(Last, From, To, out var range); if (!string.IsNullOrEmpty(getRangeResult?.ErrorMessage)) { ConsoleHelper.WriteError(getRangeResult.ErrorMessage); return; } var sas = Prompt.GetPassword("Shared Access Signature:", ConsoleColor.White, ConsoleColor.DarkBlue); Console.CancelKeyPress += ConsoleOnCancelKeyPress; try { ConsoleHelper.WriteDebug( $"Querying 'WADLogsTable' from storage account '{StorageAccountHelper.GetStorageAccountName(sas)}' from {range}..."); var repository = new Repository(sas); var logs = await repository.GetLogsAsync(range, Token); ConsoleHelper.WriteDebug($"Writing {logs.Count} log event(s)..."); using (var outputFile = File.CreateText(fullPath)) { outputFile.WriteLine("Generated,Level,Message"); foreach (var log in logs) { outputFile.WriteLine(log); } } Console.WriteLine(); ConsoleHelper.WriteDebug("Done"); } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Exception: {0}", e.GetType()); Console.WriteLine("Message: {0}", e.Message); Console.WriteLine("StackTrace:"); Console.WriteLine(e.StackTrace); } finally { Console.ResetColor(); } }
private async Task OnExecuteAsync() { var outputFilePath = Path.GetFullPath(OutputFilePath); var getRangeResult = RangeParser.TryGetRange(Last, From, To, out var range); if (!string.IsNullOrEmpty(getRangeResult?.ErrorMessage)) { ConsoleHelper.WriteError(getRangeResult.ErrorMessage); return; } var sas = Prompt.GetPassword("Shared Access Signature:", ConsoleColor.White, ConsoleColor.DarkBlue); Console.CancelKeyPress += ConsoleOnCancelKeyPress; try { if (Prefix.Last() != '/') { Prefix += "/"; } ConsoleHelper.WriteDebug($"Querying storage account '{StorageAccountHelper.GetStorageAccountName(sas)}' from {range}"); var from = range.From; var to = range.To ?? DateTime.UtcNow; var datePrefixes = PrefixService.BuildBlobPrefixes(from, to, Prefix); var repository = new Repository(sas, Container); var blobs = new List <CloudBlockBlob>(); foreach (var datePrefix in datePrefixes) { blobs.AddRange(await repository.ListLogBlobsAsync(datePrefix, CancellationToken.None)); } var tempDirectory = Path.Combine(Path.GetTempPath(), "wad-to-csv", Path.GetRandomFileName().Replace(".", string.Empty)); Directory.CreateDirectory(tempDirectory); var filtered = PrefixService.Filter(blobs, from, to, Prefix); await repository.DownloadLogBlobsAsync(filtered, tempDirectory, CancellationToken.None); CsvWriter.Write(from, to, tempDirectory, outputFilePath); Console.WriteLine(); ConsoleHelper.WriteDebug("Done"); } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Exception: {0}", e.GetType()); Console.WriteLine("Message: {0}", e.Message); Console.WriteLine("StackTrace:"); Console.WriteLine(e.StackTrace); } finally { Console.ResetColor(); } }